Database / Google Spanner Database Interview questions
Describe primary keys in Google Spanner schema design?
Every Spanner table requires a primary key, and unlike most relational databases, that key also decides how rows are physically distributed across storage splits. Rows are stored in primary-key order, so the key you choose directly controls which machine handles which rows.
This makes primary key choice a performance decision, not just a uniqueness rule. A key that increases monotonically, like an auto-incrementing integer or a timestamp, sends all new writes to the same split, creating a hotspot. Common fixes include prefixing the key with a hashed or shuffled value, using a UUID, or bit-reversing a sequential ID so consecutive values land on different splits. Composite keys are also used to support interleaved parent-child relationships.
More Related questions...