educative.io

Number of bytes needed for photo id

What could be the size of our PhotoID ? Let’s say our epoch time starts today; how many bits we would need to store the number of seconds for the next 50 years?

86400 sec/day * 365 (days a year) * 50 (years) => 1.6 billion seconds

We would need 31 bits to store this number. Since, on average, we are expecting 23 new photos per second, we can allocate 9 additional bits to store the auto-incremented sequence. So every second, we can store (2^9 => 512)(2​9​​=>512) new photos. We are allocating 9 bits for the sequence number which is more than what we require; we are doing this to get a full byte number (as 40 bits = 5 bytes40bits=5bytes). We can reset our auto-incrementing sequence every second.

Is the 5 bytes only for the auto-incrementing ID. We also need 4 bytes for epoch time. As a result, we need a total of 9 bytes for the photo ID.