Databases & caching · Capacity design
How many connections does the sale need?
Size the database connection pools of a service for a known peak. How many connections does each instance need, and how many can the database take?
Capacity design · checkout-service and its PostgreSQL serverIllustrative scenario, not a real incident
The sale opens on Friday at 20:00, and a teammate proposes raising every connection pool to 100
The checkout service runs 20 instances in front of one PostgreSQL server. Each instance has a HikariCP pool with its default settings. A request takes one connection, runs four queries on it and gives it back.
Last year's sale peaked at 3,000 requests a second. The team has measured the queries under load, and a hotfix deploy during the sale is likely. Autoscaling is switched off for the evening.
What the dashboards and logs show
- Peak rate
- 3,000 requests a second
- Per request
- 4 queries of 5 ms each, on one connection
- Instances
- 20, and 25 while a rolling deploy runs
- max_connections
- 300, of which 10 are reserved for administrators
Estimate · scored under "Numbers"
Do the arithmetic first
Work each figure out from what is given, on paper or in your head. Round freely: an estimate counts when it is close, and the working is shown once you check.
- Peak rate
- 3,000 requests a second
- Queries per request
- 4, one after another on one connection
- Query time
- 5 ms each, measured at the database
- Instances
- 20, and 25 during a rolling deploy (25% surge)
- max_connections
- 300
- Reserved slots
- 10: 3 for superusers (the default) and 7 reserved_connections
- Callers give up after
- 5 seconds
- connections
- connections
- connections
- connections
Your rubric score, the model answer, the follow-up questions and the related lessons appear once you have answered the last step.