System Design · Module 05
Database scaling: read replicas, sharding and partitioning
- Lessons
- 12
- Free
- 0
- Reading
- ~4 h
Your progress
0 / 12 lessons done
Sign in to trackLessons
- Scaling a relational database: the optionsA slow database does not tell you which scaling option will help. You need to identify the constrained resource before changing capacity, routing or data placement.
- Read replicas and replication lagRead replicas can take browsing traffic off a busy database. You need to know which reads can move, what a successful write promises, and how to stop stale data from breaking a user’s workflow.
- Connection pooling: reusing database connectionsAdding app servers can exhaust database connections before the database runs out of query capacity. Pooling controls that pressure, but only when connection ownership, waiting and fleet-wide limits are explicit.
- Sharding: splitting data across databasesSplitting a database changes more than storage capacity. It changes routing, transaction boundaries, failure recovery and the queries your service can answer cheaply.
- Hot partitions: uneven load across shardsA database cluster can have spare capacity and still reject requests. You need to find the overloaded routing unit before adding machines or changing the data model.
- Consistent hashing: adding servers without moving most dataAdding database capacity can create a second problem: relocating existing data. Consistent hashing limits changes in ownership, but you still need a safe way to move records and update routers.
- Resharding: rebalancing data without downtimeAdding database capacity requires moving existing data while customers keep changing it. The difficult part is transferring ownership without losing acknowledged writes.
- Distributed ID generation: unique IDs across machinesServices often need an identifier before saving data. Once several machines generate those identifiers, uniqueness depends on more than incrementing a counter.
- UUID vs Snowflake IDs: choosing an ID formatAn ID format becomes part of database keys, URLs, events and support tools. Choosing it also means choosing the failures your system must prevent.
- Ticket servers: generating IDs from a central counterA shared counter can give sharded databases unique integer IDs without depending on clocks. Its safety depends on preserving allocation history through retries, process restarts and database failover.
- Clock skew: why server clocks disagreeClocks influence request deadlines, event histories and distributed IDs. A clock correction can expose assumptions that ordinary load testing never exercises.
- Design: a URL shortener for millions of usersSmall lookup services become difficult when links must survive failures, traffic concentrates on one key, and cached answers outlive changes. This design connects database scaling techniques into one working system.
Practise with
Terms this module teaches 44
Open glossaryAsynchronous replication
Replication where the source can acknowledge a committed write without waiting for a replica to acknowledge it.
Change data capture
Exposing committed database changes for another system to consume.
Clock drift
The change in a clock’s offset as it runs faster or slower than a reference.
Clock offset
The difference between a clock reading and a reference clock at one instant.
Clock skew
Disagreement between the readings of different clocks at the same instant.
Co-location
Keeping related rows on the same database shard so common operations can stay local.
Connection acquisition timeout
The maximum time an operation waits to obtain a connection from a pool before acquisition fails.
Connection pool
A bounded set of reusable database connections that an application borrows and returns.
Distributed ID generation
Generating identifiers on several machines while preserving the required uniqueness scope.
Epoch
A fixed starting instant used as the reference point for a timestamp.
Fencing
Preventing an old or unauthorized writer from changing protected state after ownership has changed.
Hash ring
A circular ordering of hash positions where a key belongs to the first shard token at or after its position, wrapping to the beginning when necessary.
High-water mark
A recorded upper boundary through which values or work have already been reserved or processed.
Hot partition
A routed group of data whose requests demand more work than its assigned resources can serve.
ID collision
Two different entities receive the same identifier within a namespace where identifiers should be unique.
ID range
A consecutive set of IDs reserved exclusively for one allocator consumer.
Logical bucket
A stable grouping of keys that can be assigned to a physical database shard.
Logical partition
Records grouped by a routing key and assigned together to a storage destination.
Logical shard
A stable bucket of records whose placement can change independently of the rule assigning records to it.
Migration checkpoint
A durable record of completed migration work that allows safe restart.
Migration fence
An enforced gate preventing an old data owner from accepting operations after ownership transfer begins.
Monotonic clock
A clock whose successive readings do not go backward, used for elapsed-time comparisons within its clock domain.
Network Time Protocol
A protocol that uses timestamp exchanges to estimate clock differences and synchronize computer clocks.
Partition key
The field or fields that identify a partition and determine data placement under a database’s partitioning scheme.
Read replica
A database copy that receives changes from another database and can serve read queries.
Replica
One node’s copy of data that is also stored on other nodes.
Replication
Keeping copies of the same data on multiple nodes by transferring changes between them.
Replication lag
The delay between a change on a source database and that change becoming available on a replica.
Resharding
Changing how existing data is distributed across database shards.
Routing epoch
A generation number identifying a particular ownership assignment for a data partition.
Scatter-gather
Sending a query to several shards and combining their results.
Shard key
The data value used to determine which shard owns a row.
Sharding
Dividing a dataset into subsets stored in separate databases.
Snowflake-style ID
A compact integer identifier that combines a timestamp offset, a generator identifier and a sequence within a timestamp.
Synchronous replication
Replication where acknowledging a write requires selected replicas to confirm a configured stage, such as persistence or application.
Table partitioning
Dividing a logical table into separately managed pieces; those pieces can remain within one database instance.
Ticket server
A service that reserves unique numeric IDs from a shared counter before applications use them.
Tombstone
A retained record showing that an item is no longer active, even when its original data has been removed.
Transaction pooling
Sharing database connections by assigning one to a client for a transaction and releasing it when that transaction ends.
UUID
A 128-bit identifier whose version determines how it is generated, such as from randomness or a timestamp with additional uniqueness fields.
UUIDv7
A UUID format that starts with a Unix-millisecond timestamp and uses the remaining non-format bits for randomness or optional ordering mechanisms.
Vertical partitioning
Separating data by tables or fields rather than splitting records of the same kind across machines.
Wall clock
A clock that represents calendar date and time and may be corrected to follow a time reference.
Write salting
Adding a bucket value to a routing key so independent records from one busy group can use several destinations.