Workload-based capacity estimation

You turn browsing assumptions into request and database load estimates, then compare connection and storage demands with available resources.

Learning outcomes

  • Convert registered users into HTTP requests per second and database queries per second.
  • Apply Little's Law to estimate active database connections and choose a pool size with headroom.
  • Estimate catalogue storage from row and index sizes, then compare it with the InnoDB buffer pool.
  • Account for the opening-hours index and Redis rate limiter when estimating request-path work.
  • Identify the first likely bottleneck and determine which measurements would confirm it.

At dinner time, thousands of customers may browse restaurants within a few minutes. You have built the restaurant list, menu endpoint, menu configurator and open-hours index. Now you need to estimate whether the application and its MySQL database can handle the traffic.

You do not need a production cluster to make a first estimate. You need a workload, an estimate of the work each request performs, and an understanding of the resources available to execute that work.

This is Capacity estimation: estimating how much work a system can handle before a resource becomes a bottleneck. The result is a starting hypothesis, not a guarantee of production performance.

Workload assumptions

Capacity estimates start with user activity, not server specifications. A server's CPU count or database connection limit tells you little until you know what users ask it to do.

Use three quantities to describe the workload.

Requests per second (RPS) is the number of HTTP requests arriving in one second. It gives you a common unit for describing incoming traffic.

Database queries per second (QPS) measures the number of database statements executed per second. It can be higher than HTTP RPS because one endpoint request may execute several SQL statements.

A peak factor describes how much busier the system becomes during a high-traffic period than during an average period. A factor of three means peak traffic is three times the average traffic.

The distinction matters because a system that handles average traffic comfortably may still struggle during the evening peak.

For this example, assume one application server and one MySQL server. Each has four vCPUs. You will estimate their workload separately.

The Week 2 request costs

Your Week 2 API has two important read operations:

  • GET /v1/restaurants returns a page of restaurants using keyset pagination.
  • GET /v1/restaurants/{id}/menu returns a restaurant's menu using at most five SQL statements.

These endpoints have different database costs.

The listing endpoint executes one database query. The query uses the restaurant listing filters and pagination conditions.

The menu endpoint executes at most five database statements. Those statements retrieve menu data in batches rather than issuing a separate query for every item.

For capacity planning, use the maximum of five queries per menu request. Actual requests may use fewer.

One restaurant-list request:
    1 database query

One menu request:
    At most 5 database queries

This distinction means one HTTP request does not necessarily equal one database query.

For example, 100 listing requests and 100 menu requests can generate:

100 listing requests x 1 query = 100 queries

100 menu requests x 5 queries = 500 queries

Total = 600 database queries

The database workload depends on both incoming HTTP traffic and the number of SQL statements executed by each endpoint.

You should therefore calculate HTTP RPS and database QPS separately.

Connection pool sizing

Connection pool sizing means choosing how many database connections your application should keep available for executing queries.

Your Go application uses database/sql to manage a connection pool. The pool reuses connections instead of establishing a new network connection for every query.

It also limits how many connections can be open simultaneously.

The relevant settings include:

  • SetMaxOpenConns: the maximum number of open connections.
  • SetMaxIdleConns: the maximum number of connections retained idle for reuse.
  • SetConnMaxLifetime: the maximum lifetime of a connection.
  • SetConnMaxIdleTime: the maximum time an idle connection is retained.

For capacity estimation, SetMaxOpenConns is the main setting. It determines how many database operations can hold connections concurrently through that pool.

Connection concurrency

HTTP request count and database connection count are different quantities.

Suppose your application receives 1,000 HTTP requests per second. Each request executes one database query, and each query occupies a connection for 2 milliseconds.

The average number of concurrently occupied connections is approximately:

concurrent queries = query RPS x query time

concurrent queries = 1,000 x 0.002

concurrent queries = 2

This is an application of Little's Law. The average number of items in a system equals their arrival rate multiplied by their average time in the system.

For database connections, use the time a query occupies its connection, not the total time a customer spends waiting for an HTTP response.

Although 1,000 queries arrive every second, each occupies a connection for only 2 milliseconds. Approximately two connections are therefore executing queries concurrently on average, assuming the database can sustain that arrival rate.

You still need additional capacity for bursts, uneven query durations and scheduling delays.

Pool size and headroom

A useful starting calculation is:

required active connections =
    database queries per second x average query time

pool target =
    required active connections x headroom factor

Express query time in seconds.

For example, suppose your application executes 2,000 queries per second and each query occupies its connection for 1 millisecond:

query time = 1 / 1,000

query time = 0.001 seconds

active connections = 2,000 x 0.001

active connections = 2

With a headroom factor of two:

pool target = 2 x 2

pool target = 4 connections

This is an initial estimate. You must validate the pool under load.

The headroom factor accounts for variation in query duration and traffic. It is not a substitute for measuring the actual workload.

The cost of an oversized pool

Increasing the connection pool whenever requests start waiting can make the database slower.

MySQL has limited CPU, memory, storage throughput and internal resources. It cannot execute an unlimited number of queries simultaneously.

Consider a MySQL server with four CPU cores. If you allow hundreds of connections to execute expensive queries simultaneously, those queries compete for CPU time, memory, locks and other resources.

More concurrency can produce:

  • More context switching.
  • Greater memory consumption.
  • More contention for database resources.
  • Longer query execution times.
  • Longer queues waiting for resources.

If MySQL can comfortably process ten concurrent queries, allowing 100 queries to compete for execution does not create ten times the capacity.

Instead, the additional connections may increase the time each query takes. This can increase connection occupancy and make the application wait even longer.

A connection pool should be large enough to keep the database productively occupied, but not so large that it overwhelms the database.

MySQL connection limits

MySQL also has a server-wide max_connections setting.

Inspect the configured value:

sql
SHOW VARIABLES LIKE 'max_connections';

For the worked example, assume the server is configured for 151 connections.

This limit applies to all clients connected to that MySQL server, not to each application instance separately.

If three application instances each allow 100 connections, their combined potential usage is 300 connections. That exceeds a server limit of 151 before you account for administrative access or other services.

You must also reserve connections for monitoring, migrations, background jobs and operational access.

The configured maximum is not a recommendation to use every available connection. A pool of ten against a server limit of 151 leaves room for other clients, provided the aggregate usage of all instances stays within the server limit.

Catalogue storage estimation

Storage estimation is the process of estimating how much storage a dataset needs using its row sizes, indexes and internal overhead.

It helps you answer two separate questions:

  1. How much storage does the catalogue occupy?
  2. Can MySQL keep the frequently accessed catalogue pages in memory?

These questions are related, but they are not identical. A database can have several gigabytes of data on disk while keeping its frequently accessed pages in memory.

Row and index storage

Start with the number of rows and an approximate average storage requirement per row.

For an initial estimate:

table storage = row count x average row size

However, InnoDB tables occupy more space than the application columns alone.

InnoDB maintains record metadata and index structures. Its primary index is a clustered index: table rows are stored in primary-key order within that structure.

Additional lookup paths use secondary indexes. InnoDB secondary-index entries also contain the primary-key value needed to locate the corresponding clustered record.

A rough storage estimate therefore includes both rows and their indexes:

total storage =
    row storage + index storage + overhead

You can combine the terms into one estimate when you know the average index storage per row:

total storage =
    row count x (row bytes + index bytes per row)

For example, suppose a table contains 1,000,000 rows. Each row averages 200 bytes, with another 100 bytes of index storage per row.

row storage = 1,000,000 x 200

row storage = 200,000,000 bytes

index storage = 1,000,000 x 100

index storage = 100,000,000 bytes

estimated total = 300,000,000 bytes

That is approximately 300 MB using decimal units.

This is an estimate, not an exact prediction of the physical database file size. Actual storage depends on column types, variable-length values, page utilization, index structure, fragmentation and internal overhead.

The assumptions become more important as the dataset grows. A 10 percent error on a small table may not matter, but the same error across millions of rows can mean hundreds of megabytes.

The InnoDB buffer pool

InnoDB uses a buffer pool to cache database pages in memory.

When a query needs a page, MySQL first checks whether that page is already in the buffer pool. If it is present, MySQL can read it from memory instead of fetching it from storage.

Memory access is generally much faster than storage access. Keeping frequently accessed pages in the buffer pool therefore helps reduce read latency.

For a dedicated MySQL server, allocating around 70 percent of available RAM to the buffer pool is a common starting point. You must leave room for the operating system, MySQL memory outside the buffer pool, connections and other processes.

For a machine with 16 GB of RAM:

available RAM = 16 GB

buffer pool allocation = 16 x 0.70

buffer pool allocation = 11.2 GB

The remaining memory is:

remaining RAM = 16 - 11.2

remaining RAM = 4.8 GB

Do not assume that every byte of the buffer pool is available for table rows. Index pages also occupy space, and MySQL needs room for other working operations.

Working set and total database size

The working set is the portion of database data and indexes that your workload accesses frequently enough to benefit from keeping it in memory.

It can be much smaller than the complete database.

For example, your restaurant listing endpoint repeatedly accesses restaurant records and their indexes. The menu endpoint repeatedly accesses menu records belonging to popular restaurants.

If the frequently accessed pages fit in the buffer pool, many reads can be served from memory.

If the working set is substantially larger than the buffer pool, MySQL must repeatedly fetch pages from storage. This can increase query latency, especially when requests access many different parts of the catalogue.

Compare your estimated working set with the available buffer pool, not only the total database file size with physical RAM.

Worked capacity example

Now apply these calculations to a concrete deployment.

You have 500,000 registered users. You want to estimate the traffic generated during a busy evening and determine whether one application server and one MySQL server can handle it.

The assumptions are deliberately explicit. They describe one possible workload on commodity hardware, not guaranteed performance figures for Go or MySQL 8.4.

Browsing demand

Assume:

  • 500,000 registered users.
  • 8 percent browse restaurants during a busy evening.
  • Each browsing user opens the restaurant list six times.
  • Each browsing user opens three restaurant menus.
  • All this activity occurs within a ten-minute window.
  • The peak factor is three.

First calculate the number of browsing users:

registered users = 500,000

browsing percentage = 8 / 100 = 0.08

browsing users = 500,000 x 0.08

browsing users = 40,000

Therefore, 40,000 users browse the restaurant catalogue during the ten-minute window.

This does not mean all 40,000 users send requests simultaneously. Their activity is distributed across the window.

HTTP request rate

Each browsing user performs six listing requests and three menu requests:

listing requests per user = 6

menu requests per user = 3

total requests per user = 6 + 3

total requests per user = 9

Across all 40,000 users:

total listing requests = 40,000 x 6

total listing requests = 240,000

total menu requests = 40,000 x 3

total menu requests = 120,000

total HTTP requests = 240,000 + 120,000

total HTTP requests = 360,000

Ten minutes contains 600 seconds.

The average HTTP request rate is:

average HTTP RPS = 360,000 / 600

average HTTP RPS = 600

Apply the peak factor:

peak HTTP RPS = 600 x 3

peak HTTP RPS = 1,800

Your application should therefore be evaluated against approximately 1,800 HTTP requests per second during the assumed peak.

It is useful to keep the endpoint rates separate:

average listing RPS = 240,000 / 600

average listing RPS = 400

average menu RPS = 120,000 / 600

average menu RPS = 200

At peak:

peak listing RPS = 400 x 3

peak listing RPS = 1,200

peak menu RPS = 200 x 3

peak menu RPS = 600

These separate rates will make the database calculation easier.

Database query rate

The listing endpoint executes one database query per request. The menu endpoint executes at most five database queries per request.

For capacity planning, use five for every menu request. This gives you an upper-bound estimate.

Calculate the total database queries:

listing queries = 240,000 x 1

listing queries = 240,000

menu queries = 120,000 x 5

menu queries = 600,000

total database queries = 240,000 + 600,000

total database queries = 840,000

Divide by the 600-second window:

average database QPS = 840,000 / 600

average database QPS = 1,400

Apply the peak factor:

peak database QPS = 1,400 x 3

peak database QPS = 4,200

The endpoint breakdown at peak is:

listing database QPS = 1,200 x 1

listing database QPS = 1,200

menu database QPS = 600 x 5

menu database QPS = 3,000

total database QPS = 1,200 + 3,000

total database QPS = 4,200

The result is:

peak HTTP RPS = 1,800

peak database QPS = 4,200

The database receives more operations than the API receives HTTP requests because menu requests execute up to five SQL statements.

Database connection requirements

Assume the following average database connection-occupancy times:

  • Listing query: 1.5 milliseconds.
  • Complete menu database operation: 4 milliseconds across its five batched queries.

The menu figure represents the combined time spent executing its database statements, not the total time the customer waits for the HTTP response.

Calculate the database time per browsing user:

listing database time = 6 x 1.5 ms

listing database time = 9 ms

menu database time = 3 x 4 ms

menu database time = 12 ms

total database time per user = 9 + 12

total database time per user = 21 ms

There are 21 database queries per user:

database queries per user = 6 + (3 x 5)

database queries per user = 21

The weighted average connection-occupancy time per query is:

average query time = 21 ms / 21

average query time = 1 ms

average query time = 0.001 seconds

Now apply Little's Law to the peak database query rate:

peak database QPS = 4,200

average query time = 0.001 seconds

active database queries = 4,200 x 0.001

active database queries = 4.2

The database needs approximately 4.2 concurrently executing queries on average to sustain this assumed peak arrival rate.

You cannot configure a fractional connection. You also should not size the pool exactly to the average requirement.

Choose a headroom factor of approximately two:

required active connections = 4.2

headroom factor = 2

pool target = 4.2 x 2

pool target = 8.4

You need to round up to a whole connection. Choose a maximum of ten open database connections:

go
db.SetMaxOpenConns(10)
db.SetMaxIdleConns(10)

This is a starting configuration, not a universal recommendation.

For the assumed MySQL server:

MySQL max_connections = 151

application pool = 10

remaining connection allowance = 151 - 10

remaining connection allowance = 141

Those 141 connection slots are only the remaining theoretical allowance before other application instances, workers, monitoring, migrations and administrative sessions use them.

The important result is that the estimated workload requires approximately 4.2 active database connections on average, while the application pool permits ten concurrent operations.

The pool is not expected to be saturated under these assumptions. At average traffic:

average active queries = 1,400 x 0.001

average active queries = 1.4

At peak traffic:

peak active queries = 4,200 x 0.001

peak active queries = 4.2

The difference between ten available connections and 4.2 estimated active queries provides room for variation in query duration and traffic.

However, this does not establish that MySQL can sustain 4,200 queries per second. The assumed query time must hold under concurrent load, and MySQL must have enough CPU and storage throughput.

Application CPU demand

Assume each HTTP request requires 1 millisecond of Go CPU time, excluding database execution.

This includes request handling, JSON encoding, validation and assembling the response.

At peak traffic:

peak HTTP RPS = 1,800

Go CPU time per request = 0.001 seconds

Go CPU seconds per second = 1,800 x 0.001

Go CPU seconds per second = 1.8

One CPU core provides approximately one CPU-second of execution per second.

The application therefore requires approximately 1.8 CPU cores for this assumed request-processing workload.

On a four-vCPU application machine:

available CPU cores = 4

estimated Go CPU cores = 1.8

remaining CPU capacity = 4 - 1.8

remaining CPU capacity = 2.2 cores

The assumed Go request-processing work uses 45 percent of the available CPU capacity.

This calculation excludes operating-system overhead, garbage collection and background tasks. It also excludes database CPU consumption because the example uses separate four-vCPU application and MySQL machines.

The application appears to have CPU headroom under these assumptions. You still need to measure actual CPU usage under concurrent requests.

Catalogue storage

Now estimate the storage required for 50,000 restaurants, each containing 40 items.

restaurants = 50,000

items per restaurant = 40

total item rows = 50,000 x 40

total item rows = 2,000,000

The simplified catalogue contains:

restaurant rows = 50,000

item rows = 2,000,000

total rows = 2,050,000

For this estimate, assume the following average storage requirements:

Record typeRow storageIndex storage per row
Restaurant256 bytes64 bytes
Item256 bytes96 bytes

These are illustrative estimates, not measurements of your actual schema. The row sizes include an approximate allowance for record metadata. The index allowances represent the assumed primary and secondary index storage.

Calculate restaurant storage:

restaurant row storage = 50,000 x 256

restaurant row storage = 12,800,000 bytes

restaurant index storage = 50,000 x 64

restaurant index storage = 3,200,000 bytes

total restaurant storage =
    12,800,000 + 3,200,000

total restaurant storage = 16,000,000 bytes

That is approximately 16 MB.

Now calculate item storage:

item row storage = 2,000,000 x 256

item row storage = 512,000,000 bytes

item index storage = 2,000,000 x 96

item index storage = 192,000,000 bytes

total item storage =
    512,000,000 + 192,000,000

total item storage = 704,000,000 bytes

That is approximately 704 MB.

Combine the two:

restaurant storage = 16,000,000 bytes

item storage = 704,000,000 bytes

catalogue storage = 720,000,000 bytes

catalogue storage = approximately 0.72 GB

This estimate covers only the restaurant and item tables and their assumed indexes.

It does not include every table in the Week 2 schema. The item_sizes, option_groups, options, option_prices, and open_slots tables, along with migration metadata and other application data, will increase the actual total.

The real storage requirement also depends on InnoDB page utilization, variable-length values, index structure and fragmentation.

Buffer-pool capacity

Assume the MySQL server has 16 GB of RAM.

Allocate 70 percent to the InnoDB buffer pool:

server RAM = 16 GB

buffer pool percentage = 0.70

buffer pool size = 16 x 0.70

buffer pool size = 11.2 GB

Compare the estimated catalogue size with the buffer pool:

catalogue size = 0.72 GB

buffer pool size = 11.2 GB

remaining buffer pool capacity = 11.2 - 0.72

remaining buffer pool capacity = 10.48 GB

The estimated restaurant and item catalogue occupies approximately:

catalogue percentage = (0.72 / 11.2) x 100

catalogue percentage = 6.43%

Under these assumptions, the simplified catalogue fits comfortably inside the available buffer pool.

This is a favourable starting point for a read-heavy restaurant API. Frequently accessed restaurant and menu pages can potentially be served from memory instead of repeatedly fetching them from storage.

However, fitting the catalogue into memory does not mean every query is automatically fast. Indexes must still be appropriate, queries must avoid unnecessary work, and the buffer pool must accommodate other tables and frequently accessed pages.

You should also distinguish the estimated physical storage size from the actual buffer-pool footprint. Database files and cached InnoDB pages are not identical measurements.

Opening-hours and Redis workload

The database query count is not the entire request-path cost. The Week 2 API also performs opening-status lookups and rate-limit checks.

The in-memory open-hours index

The restaurant list includes an is_open value for every returned restaurant. It reads this value from the in-memory open-hours index built in the previous module.

A background Goroutines loads the open_slots records and rebuilds the index every HOURS_REFRESH_INTERVAL. The default interval is 1m.

The refresher publishes a complete immutable snapshot through an atomic.Pointer. Request handlers read the current snapshot instead of querying open_slots for each restaurant.

This means a listing request does not need an additional SQL query for every is_open value. A page containing 20 restaurants still uses the in-memory index for opening-status checks.

The refresh has a database cost, but it is separate from listing traffic. Each API instance performs its own background refresh. With multiple instances, the total refresh work grows with the number of instances and the configured refresh frequency, not with the number of listing requests.

The distinction is important at the example's peak listing rate:

peak listing RPS = 1,200

opening-status lookups per listing request = memory lookups

additional open_slots queries per listing request = 0

Without the in-memory index, the application could repeatedly query opening-hours records while constructing listing responses. That would increase MySQL demand as listing traffic grows.

The index does not eliminate the need to refresh opening hours correctly. It moves repeated read work away from the database request path.

Redis rate limiting

The API also rate-limits requests per user using a Redis fixed-window counter.

A fixed-window counter tracks how many requests a user makes during a time window. A common implementation increments a counter associated with the user and gives that counter an expiry.

When multiple Redis commands must work together, use an atomic operation such as a Redis transaction or an appropriate server-side script. For example, incrementing a counter and assigning its expiry should not depend on two unrelated operations that can be separated by a failure.

The exact number of Redis commands depends on the implementation. For capacity planning, remember that every incoming API request also creates rate-limit work.

At the assumed peak:

peak HTTP RPS = 1,800

logical rate-limit checks per request = 1

logical rate-limit checks per second = 1,800

If each check uses multiple Redis commands, the actual command rate will be higher. Measure Redis command throughput and latency rather than treating every HTTP request as exactly one Redis operation.

The rate limiter in this API uses a fail-open policy. If Redis is unavailable, the API allows the request through instead of denying every user access.

This preserves API availability when the rate-limit dependency fails. However, it also means rate limiting no longer protects the application or MySQL during that outage.

A Redis failure can therefore turn a controlled workload into unrestricted incoming traffic. Monitor Redis failures and backend load together. Do not assume the rate limiter will protect downstream services when its dependency is unavailable.

The likely bottleneck

The worked example produces these peak estimates:

Resource or workloadEstimate
HTTP requests1,800 RPS
Restaurant-list requests1,200 RPS
Menu requests600 RPS
MySQL queries4,200 QPS
Average active database queries4.2
Application CPU demand1.8 of 4 cores
Application connection pool10 connections
Simplified catalogue storage0.72 GB
InnoDB buffer pool11.2 GB
Logical Redis rate-limit checks1,800 per second

The model does not prove which resource will fail first. It tells you which assumptions need measurement.

You should investigate MySQL query throughput first. It must sustain approximately 4,200 queries per second, but you have not established how much work the four-vCPU MySQL server can actually complete.

The connection pool does not appear to be the first constraint under the assumed 1 millisecond average query time. Estimated average peak concurrency is 4.2, compared with ten available connections.

The simplified catalogue also fits comfortably inside the estimated buffer pool. Application CPU demand is approximately 1.8 cores on a four-vCPU machine.

That leaves MySQL query execution as the main unvalidated capacity assumption. Redis throughput is another dependency that needs measurement.

Application CPU

Go request processing consumes approximately 45 percent of the assumed application CPU capacity.

As traffic grows, CPU demand grows with request volume. Eventually, JSON encoding, validation, garbage collection or other application work may increase request latency.

Measure CPU utilization and profile handlers before adding application instances.

MySQL throughput

MySQL must execute approximately 4,200 queries per second at the assumed peak.

Poor query plans, missing indexes, excessive sorting, lock contention or unexpectedly expensive queries can increase execution time.

Use EXPLAIN to inspect the actual query plans for the restaurant list and menu queries.

Check the chosen key, access type and estimated rows. A query that returns the correct data can still examine far more rows than necessary.

An index existing in the schema does not guarantee that MySQL will use it for every query.

Connection pool contention

If queries become slower, each query holds its connection for longer.

Little's Law shows the relationship:

active connections =
    query RPS x average query execution time

If the average query time doubles while the arrival rate stays the same, the estimated concurrent database work also doubles.

Requests may then wait for an available connection.

Before increasing the pool, determine whether MySQL has spare CPU and memory capacity. Increasing the pool when MySQL is already saturated can increase contention and make queries slower.

Memory and storage pressure

The simplified catalogue fits inside the assumed buffer pool, but the actual database also contains option tables, additional indexes and other data.

As the working set grows, MySQL may need to fetch more pages from storage. That can increase query latency even when CPU and connection limits appear healthy.

Redis and infrastructure

The rate limiter performs work on the request path. Measure Redis command latency and throughput under the same traffic distribution as the API.

Network throughput, connection handling and response sizes also become relevant as traffic increases. A menu response may consume substantially more bandwidth than a small restaurant-list response, even though both count as one HTTP request.

The bottleneck order is a starting hypothesis, not a universal sequence. Actual measurements determine which resource becomes constrained first.

Capacity validation

Every figure in this lesson is an estimate.

The assumed 1.5 ms listing query, 4 ms menu database operation, 1 ms Go CPU cost and row sizes are not measured properties of your implementation.

Later in the course, load testing turns these estimates into measurements. You generate realistic traffic and compare observed resource usage with your calculations.

Load testing

Use a workload that exercises both endpoints:

  • Repeated calls to GET /v1/restaurants with realistic pagination.
  • Repeated calls to GET /v1/restaurants/{id}/menu across different restaurants.

The workload should approximate the assumed distribution of six listing requests for every three menu requests.

Increase traffic gradually rather than starting immediately at the target peak.

Measure:

  • HTTP requests per second.
  • Response latency, especially p95 and p99.
  • HTTP error rates.
  • Application CPU and memory.
  • Database connection pool usage.
  • Database query rates and query latency.
  • Redis command throughput and latency.

A system that reports 1,800 RPS but returns errors or has extremely high p99 latency is not successfully handling the workload.

Query plan inspection

Use MySQL's EXPLAIN to inspect the execution plans for your listing and menu queries.

Run it on the same SQL shape with representative values from your database. Check whether MySQL uses the expected index and whether the query examines a reasonable number of rows.

A query plan can reveal unexpected table scans, inefficient access methods and expensive sorting.

Small test tables may lead the optimizer to choose a table scan because it is cheaper for a tiny dataset. That does not necessarily mean the production query will use the same plan.

Treat the schema definition and the actual execution plan as separate things to inspect.

Redis and background work

The Redis rate limiter is another dependency whose capacity matters.

Use representative request traffic when measuring Redis. A synthetic benchmark such as redis-benchmark can provide an initial indication of throughput, but it does not reproduce your application's command distribution or network conditions.

If the fixed-window counter uses multiple operations, verify that they execute with the intended atomic behavior. Measure how the API behaves when Redis becomes unavailable, including the additional traffic that can reach the backend under the fail-open policy.

For the opening-hours index, measure refresh duration and check that background work does not interfere with request processing.

Comparing estimates with measurements

When the load test reaches the target workload, compare observations with the original assumptions:

Estimated peak HTTP RPS = 1,800

Measured peak HTTP RPS = from load test

Estimated peak database QPS = 4,200

Measured database QPS = from MySQL metrics

Estimated active connections = 4.2

Measured active connections = from database metrics

Estimated Go CPU demand = 1.8 cores

Measured Go CPU usage = from application metrics

Suppose the measured average query time is 3 milliseconds instead of the assumed 1 millisecond.

The connection estimate changes:

peak database QPS = 4,200

average query time = 0.003 seconds

active database queries = 4,200 x 0.003

active database queries = 12.6

With a headroom factor of two:

pool target = 12.6 x 2

pool target = 25.2

rounded pool size = 26

That is substantially different from the original pool size of ten.

However, do not immediately configure 26 connections. First establish whether the higher query time comes from CPU saturation, disk reads, locking, inefficient queries or another constraint.

The purpose of estimation is to know what to investigate, not to replace measurement.

The Week 2 capacity model

You estimated a restaurant API workload using a concrete browsing pattern.

The worked example produced these results:

MeasurementEstimated value
Registered users500,000
Browsing users40,000
HTTP requests over ten minutes360,000
Average HTTP RPS600
Peak HTTP RPS1,800
Average database QPS1,400
Peak database QPS4,200
Average peak active queries4.2
Chosen connection pool10
Go CPU demand at peak1.8 cores
Simplified catalogue storage0.72 GB
Estimated buffer pool11.2 GB

The simplified catalogue fits comfortably inside the assumed buffer pool. The estimated connection pool also has headroom under the assumed query time.

The main uncertainty is whether the four-vCPU MySQL server can sustain 4,200 queries per second with acceptable latency. The actual database query times and application CPU usage need measurement.

The opening-hours index keeps repeated is_open calculations out of the restaurant-list database path. Redis rate limiting adds its own request-path workload and can stop protecting the backend when its fail-open behavior is triggered.

Capacity estimation gives you a defensible starting point for testing. It does not establish production capacity until you measure the actual system.

Check your understanding

Question 1 of 4

The API has 40,000 browsing users during a ten-minute window. Each user sends six listing requests and three menu requests. The peak factor is three. What is the estimated peak HTTP request rate?

Pick an answer, then say how sure you are.

References

Everything above is explained on this page; these are where it comes from (Go, MySQL 8.4).

Finished Lesson 2.20?

Restaurant API capacity

1 items

  • 2.20Workload-based capacity estimationnot completed

Restaurant list extensions

Up next · Module 9 · 6 items · about 5 h

Start module 9