SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 34
Design the control plane for a managed database service
Customers of a managed database service click "create cluster", pick a size and a region, and expect a working primary with replicas in minutes. After that they expect the service to replace failed machines, fail over automatically, apply patches, and roll out configuration changes without them noticing. You are designing the system that does all of that, not the database engine itself.
Requirements
- Create, resize, and delete database clusters (one primary and two replicas each) through an API.
- Place replicas on hosts with enough capacity, in three different availability zones.
- Detect a failed primary and promote a replica automatically.
- Roll out engine versions and configuration changes across the fleet safely, and apply customer schema changes to a cluster.
Constraints and assumptions
- 20,000 customer clusters on 15,000 hosts in 3 regions, each region with 3 availability zones.
- A new cluster should be serving within 10 minutes; API traffic is about 50 requests per second.
- A failed primary must be replaced by a promoted replica within 30 seconds, and there must never be two writable primaries for one cluster.
- Writes acknowledged to customers must survive the loss of a single host (replication is semi-synchronous to at least one replica).
- If the control plane is down, existing databases must keep serving reads and writes.
- Average cluster holds 200 GB of data.
Out of scope for the first sketch
The storage engine and query processing · Billing and metering · Cross-region disaster recovery
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design the control plane for a managed database service
Finish your first sketch before answering these. Cross out freely.
- Walk through creating a cluster. What happens if the control plane crashes halfway through?
- The primary's host stops answering heartbeats but is still serving some clients. How do you promote a replica without ever having two writable primaries?
- The control plane is completely down for an hour. What still works, and what does not?
- You need to roll a new engine minor version to all 20,000 clusters. How do you limit the blast radius and stop automatically if it is bad?
- A whole availability zone fails. About 6,700 clusters each lose a replica and roughly a third of them lose their primary. What breaks first?
Compare afterwards: worked approaches and reading at sketchbook /questions/database-control-plane/review