educative.io

Calculation for number of possibilities using 4 bytes for LocationID

Although a four bytes number can uniquely identify 500M locations, with future growth in mind, we will go with 8 bytes for LocationID.

Why does 4 bytes identify 500M unique locations? 256^4 = 4 billion (2 ^ 32 bits)

This means that the smallest number that can uniquely identify 500 million locations is a 4 bytes number (3 bytes are not sufficient).

Oh interesting, thanks. I think it is just weird phrasing if we already have 4 billion possible unique IDs, to say

with future growth in mind, we will go with 8 bytes for LocationID

Without mentioning that we already have 8 times more links than our estimation, especially as our previous calculation:

Let’s build our system assuming that we have 500M places and 100K queries per second (QPS). Let’s also assume a 20% growth in the number of places and QPS each year

Would mean our 4 bytes would last for 12 years of growth

Agreed the phrasing can be changed here. You are right, 4byte is enough for a lot of growth. Generally, databases either offer a 4-byte or 8-byte number, nothing in between. So if we choose to go higher, we have to go with 8-bytes.

1 Like