Scrivio Interview library
LeadershipPrincipal7 min read · updated 13 November 2026

Some teams embed the shard number in every generated id, for example in the top bits of a 64-bit id, so any service can route without a lookup. Other teams keep ids opaque and route through a directory service.

As the senior technical leader setting the identifier and routing standard for the next ten years, which approach do you choose, and which long-term consequences do you weigh?

I would not put physical shard numbers in ids, because that pins every record to its first shard for as long as the id lives in URLs, partner systems and analytics. My standard would be the middle path: internal 64-bit ids that embed a logical bucket (for example 12 bits, 4,096 buckets) rather than a shard, routed through a small, cached bucket-to-shard map so buckets can move, plus separate opaque public identifiers. It is recorded as an architecture decision, because reversing an id format later is extremely expensive.

Why this question is asked

Identifiers outlive almost every other technical choice. Code gets rewritten and databases get replaced, but an order id printed on an invoice, stored by a partner or used as a key in a data warehouse stays for decades. Interviewers ask this leadership question to see whether we can weigh routing convenience today against flexibility over ten years, and whether we think about the people and systems outside our own service. In this answer, we will compare the two approaches, look at the bucket-in-id middle path and its fixed limit, consider what ids reveal to the outside world, and turn the choice into a standard with a decision record.

1A Quick Recap: Two Ways to Find a Record's Shard

In a sharded system, every request must find the shard that holds its record. One approach puts the answer in the id itself: for example, the top 10 bits of a 64-bit id hold the shard number, so any service can compute the shard with a bit shift, with no lookup and no dependency. The other approach keeps ids opaque, meaning they carry no routing meaning, and asks a directory service, usually through a local cache, which shard holds each id or each tenant.

2What Shard Bits Cost Over Ten Years

Shard bits make routing free and remove a whole service from the request path, which is very attractive. The cost appears later, the first time we need to move data. Suppose shard 17 becomes too hot and we move half its records to shard 40. Every moved record's id still says 17. We can either change the ids, which means finding and rewriting every copy of them in URLs, emails sent to customers, partner databases, logs, caches, search indexes and the warehouse, which is effectively impossible, or keep a forwarding table that says these ids with 17 actually live on 40. That forwarding table is a directory, so we have paid for both approaches.

The same happens with mergers (two companies' ids collide or need re-homing), with region splits for data residency (a European customer's records must move to an EU shard), and with any change in the number of shards. Ten years is long enough that at least one of these will happen.

3What Opaque Ids With a Directory Cost

Opaque ids let us move tenants or records freely: the directory changes, the ids do not. The price is the directory itself. It must be highly available, because every request depends on it; heavily cached, because looking it up remotely for every request would add latency; and paired with a cache invalidation protocol and ownership checks on the shards, so that stale caches cannot write to the wrong place. If the directory maps individual records rather than tenants or buckets, it also becomes large, potentially billions of entries.

4The Middle Path: A Logical Bucket in the Id

There is an approach that keeps most of both benefits. Instead of a physical shard number, the id embeds a logical bucket number, for example 12 bits for 4,096 buckets. The bucket is chosen when the record is created, often from the tenant or customer, so related records share a bucket. A small map, only 4,096 entries, says which shard holds each bucket. Every service can cache that whole map in memory and route with a shift and an array lookup, and when a bucket moves, only the map changes; the ids stay valid forever.

The price is a fixed limit. Twelve bits means at most 4,096 buckets for the life of the system, which caps how finely data can ever be spread, and it uses 12 of the 64 bits, leaving fewer for time and sequence. For most systems 4,096 is generous: even at 400 shards, each holds about 10 buckets that can move individually. But it is a number we choose once.

Java
// 64-bit id layout (one possible standard)
// [ 1 bit unused | 41 bits ms since epoch | 12 bits bucket | 10 bits sequence ]
long id = (millisSinceEpoch << 22) | ((long) bucket << 10) | sequence;
int bucketOf(long id) { return (int) ((id >>> 10) & 0xFFF); } // 0..4095
int shardOf(long id) { return bucketMap.get()[bucketOf(id)]; } // cached int[4096]
// moving bucket 1234 from shard 17 to shard 40 changes one map entry; no id changes
The three approaches over ten years
Shard bits in idBucket bits in idOpaque id + directory
Routing costa bit shiftshift + tiny cached mapcached lookup, possibly large
Moving dataids break or need forwardingmove buckets freelymove anything freely
Fixed limitmax shard countmax bucket countnone
Runtime dependencynonea small config mapan HA directory service
Mergers and region splitspainfulmove bucketseasy

5What Ids Reveal to the Outside World

Any structured id leaks information. An id with a timestamp reveals when a record was created; an increasing sequence reveals how many orders we take per day; shard or bucket bits reveal our topology. A competitor or an attacker can collect public ids and learn growth rates, or enumerate neighbouring ids to probe for records they should not see, which turns any authorization bug into a data leak.

So my standard separates internal and public identifiers. Internal ids are the efficient, structured 64-bit values used between our services and in our databases. Public ids, the ones in URLs, emails, APIs and partner integrations, are opaque random tokens, such as a 128-bit random value encoded as text, mapped to the internal id in a lookup table or an indexed column. This also gives us freedom: if the internal format ever has to change, the public ids that outside systems store do not.

6Making It a Standard

I would test the choice against our growth plan: expected shard counts in ten years, likely mergers or acquisitions, regions we may have to serve separately, and how many systems, internal and external, will store our ids. Then I would write it as an architecture decision record: the id layout, bit allocation and epoch, the bucket count and why, the public token format, the library every team must use to generate and parse ids, and the explicit statement that ids are never parsed for business meaning outside that library. The record also lists what would make us revisit it. Reversing an id format after ten years of use is one of the most expensive changes a platform can make, so this is a decision worth making slowly, once.

7Follow-up questions

Why not just use UUIDs everywhere?

Random UUIDs are opaque and globally unique, which is good, but as primary keys they scatter inserts across B-tree indexes and take 16 bytes. Time-ordered UUIDs (UUIDv7) fix most of the index problem and are a reasonable choice for internal ids if we route through a directory or carry the bucket separately. They do not embed a bucket, so routing then needs a tenant lookup.

How do you choose the bucket for a new record?

From the entity that queries and transactions are grouped by, usually the tenant or customer: hash(tenant_id) mod 4096, so all of a tenant's records share a bucket and stay together. Choosing randomly per record would scatter related data and turn simple queries into cross-shard ones.

What if 4,096 buckets turn out not to be enough?

A bucket can still be subdivided internally by another key, and very large tenants can get a second-level map, but these are workarounds. That is why the number is chosen with a large margin: buckets only need to be numerous enough that each shard holds several, so even at a thousand shards 4,096 is workable.

8Conclusion

In this answer, we compared shard bits in ids, which make routing free but pin records to their first shard for as long as the ids live outside the database, with opaque ids routed through a directory, which keep data movable at the cost of a highly available, cached lookup. The middle path embeds a logical bucket instead of a shard, so a tiny cached map routes requests and buckets move without changing ids, at the price of a bucket count fixed for life. Public identifiers should be separate opaque tokens to avoid leaking business information, and the whole choice belongs in an architecture decision record.

What to say in the interviewAbout 90 seconds aloud

Open with

The question I ask is what happens the first time data has to move. Shard bits in the id make routing free and remove a lookup dependency, but they pin each record to its original shard.

Then, if they want more

Once that id is in URLs, customer emails, partner systems and the warehouse, moving data means either changing ids everywhere, which is not possible, or keeping a forwarding table, which is a directory anyway. Opaque ids with a directory let us move anything, but the directory must be highly available, cached and invalidated properly.

So I would set a middle path as the standard: 64-bit internal ids with, say, 12 bits of logical bucket, chosen from the tenant, plus time and sequence. A 4,096-entry bucket-to-shard map is cached in every service, so routing is a shift and an array lookup, and moving a bucket changes one map entry, never an id.

The trade-off is that the bucket count is fixed for life, so I would choose it with a big margin. I would also separate public ids: opaque random tokens in URLs and APIs, because structured ids leak creation time, volume and topology and invite enumeration.

I would check it against our growth, merger and region plans and record it in an ADR, with one shared library that generates and parses ids.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "As the senior technical leader setting the identifier and routing standard for the next...": https://scrivio-interview-library.netlify.app/architecture/partitioning-and-replication/e377277ef9/