Capacity estimation
Estimate the order service's workload so you can identify likely bottlenecks and choose what to measure during load testing.
Learning outcomes
- Convert a dinner peak into orders per second and estimate concurrent work.
- Count MySQL transactions, row mutations and asynchronous messages per completed order.
- Estimate database, authentication, relay, Kafka and consumer capacity using explicit assumptions.
- Calculate outbox backlog and storage growth, then identify which measurements can confirm or reject the estimates.
A Friday dinner peak can turn a manageable order service into a system handling more than 11 orders per second. Each order creates database work, and its later state transitions create more work for the relay and notifier. You need to account for the complete lifecycle before deciding whether MySQL, application CPU, the relay or the consumer group will run out of capacity first.
This is Capacity estimation. You estimate the resources required by a workload before measuring the actual system. The result is a model to guide testing, not a production capacity guarantee.
Arrival rate and peak demand
Start with the incoming workload. Requests per second (RPS) gives you a common unit for comparing the API, database, relay and consumers.
Convert orders per minute into orders per second by dividing by 60. Use the busiest realistic period rather than sizing only for the daily average.
The Peak factor describes how much busier a short period is than the average period. A food-delivery service may receive a large share of its daily orders during Friday dinner. A system sized around the daily average can fall behind during that peak.
You can also use Little's Law to estimate how much work is in progress:
concurrent work = arrival rate x time in systemBoth values must use compatible time units. If requests arrive at 10 per second and spend an average of 0.2 seconds in the system, approximately two requests are in progress at any moment.
This distinction matters. An active user session can last several minutes without holding an HTTP connection or a database transaction for that entire period.
Work created by one order
Before estimating throughput, count the work performed by one completed order.
Your POST /v1/orders handler writes several rows inside one MySQL transaction. For an order with three lines, the initial transaction inserts:
- One row in
orders. - Three rows in
order_lines. - One row in
order_eventsrecording placement. - One row in
outbox.
That is six inserted rows in one transaction.
The initial order_events row records the PLACED status. The outbox row represents the event that the relay must eventually publish to Kafka.
The state machine creates additional work. Each successful transition updates the existing orders row using a version check, then inserts one order_events row and one outbox row. Each transition is its own transaction.
The distinction between reaching PICKED_UP and reaching DELIVERED matters when counting events. An order that reaches PICKED_UP has five events and five outbox rows: placement, acceptance, preparation, readiness and pickup. Reaching DELIVERED adds a sixth event and outbox row.
For the capacity example, assume each order completes all five transitions, including delivery. Its database workload is:
Initial placement transaction:
orders inserts = 1
order_lines inserts = 3
order_events inserts = 1
outbox inserts = 1
Initial inserted rows = 6
Initial transactions = 1
Five successful transitions:
orders updates = 5
order_events inserts = 5
outbox inserts = 5
Transition row mutations = 5 x 3
= 15
Transition transactions = 5
Total order-side row mutations = 6 + 15
= 21
Total order service transactions = 1 + 5
= 6
Total outbox rows = 1 + 5
= 6
Total Kafka messages = 6Twenty-one row mutations do not mean 21 transactions. The initial six inserts happen in one transaction. Each of the five later transitions has its own transaction. You therefore have six order service database commits per completed order.
The notifier adds more database work. It consumes each published event and writes one notifications row for that event. It also uses processed_events to deduplicate processing by event ID. For capacity estimation, count one notifier MySQL transaction per event.
The notifier commits its Kafka offset only after its database work has been saved. If processing fails, the message goes through order-events.retry and, after three attempts, to order-events.dlq.
The total number of events per order is therefore also the number of notifier transactions. For the fully delivered orders in this example, the notifier adds six transactions.
The 21 row mutations above describe the order service's writes. They do not include the notifier's processed_events and notifications writes.
MySQL write throughput
Write throughput is the number of database transactions a MySQL primary can commit per second under a particular workload and durability configuration.
It depends on transaction size, indexes, storage latency, lock contention, buffer pool behavior and commit durability. Row counts alone cannot tell you how many transactions the database can sustain.
For this estimate, assume MySQL 8.4 runs on modern commodity hardware with an SSD and default commit durability:
innodb_flush_log_at_trx_commit = 1With this setting, MySQL flushes the InnoDB redo log at transaction commit. Assume a commit takes approximately 2 ms, including the relevant flush cost.
This is an order-of-magnitude assumption, not a guaranteed measurement for a particular server.
If every commit required an independent 2 ms flush, the simplified serial reference rate would be:
commit latency = 2 ms
= 0.002 seconds
commits per second = 1 / 0.002
= 500 commits/secondThis calculation gives you a reference point. It is not a complete model of MySQL.
Group commit
MySQL can use group commit to combine the commit work of multiple transactions into shared log flushes.
When several transactions reach the commit stage close together, MySQL can flush their redo log records together rather than requiring a separate physical flush for every transaction.
One storage flush can therefore support multiple transaction commits. The practical transaction rate can exceed the simplified 500 commits per second reference.
Group commit does not remove storage limits. The redo log, storage device, CPU, transaction processing and lock contention still affect throughput.
Use 500 commits per second as a comparison point, not as a guaranteed ceiling. Actual capacity requires measurement under the workload you intend to run.
Friday dinner workload
Consider a hypothetical food-delivery service with 200,000 registered users. During a 60-minute Friday dinner window, 5% of registered users place an order. Assume the busiest minute is four times busier than the average minute.
Every number below is an assumption. The arithmetic exposes the workload; it does not predict an exact production result.
Order arrival rate
First calculate the total number of orders during the hour:
registered users = 200,000
ordering users = 200,000 x 0.05
= 10,000 users
total orders in 60 minutes = 10,000Calculate the average number of orders per minute:
average orders/minute = 10,000 / 60
= 166.6667
= 166.67 orders/minuteApply the peak factor:
peak factor = 4
peak orders/minute = 166.6667 x 4
= 666.6668
= 666.67 orders/minuteConvert the result into orders per second:
peak orders/second = 666.67 / 60
= 11.1112
= 11.11 orders/secondThe estimated peak order placement rate is approximately 11.11 orders per second.
The service does not receive 10,000 orders every minute. It receives 10,000 over the full hour, with a short peak four times higher than the average.
Requests also carry an Idempotency-Key. The API claims the key in Redis using SET NX, so a client retry with the same key can replay the stored response rather than creating another order. Do not treat every HTTP retry as a new order when estimating successful order creation.
MySQL transaction demand
Each completed order creates six order service transactions: one placement transaction and five state transition transactions.
At 11.11 orders per second:
transactions/order = 6
order service transactions/second = 11.1112 x 6
= 66.6672
= 66.67The placement endpoint itself creates one transaction per order:
placement transactions/second = 11.11The five state transitions account for the remaining transactions:
transition transactions/second = 11.1112 x 5
= 55.556
= 55.56Together:
order service transactions/second = 11.11 + 55.56
= 66.67Now calculate the order service's row mutation rate:
row mutations/order = 21
row mutations/second = 11.1112 x 21
= 233.3352
= 233.33This is the rate of order-side inserts and updates. It is not the transaction rate.
Include the notifier in the database estimate. Each of the six events per order produces one notifier transaction:
Kafka messages/order = 6
notifier transactions/second = 11.1112 x 6
= 66.6672
= 66.67Add both sources of database transactions:
order service commits/second = 66.67
notifier commits/second = 66.67
total MySQL commits/second = 66.67 + 66.67
= 133.33The primary handles approximately 133.33 transactions per second at the estimated peak. Looking only at the order API would miss half of this transaction demand.
Moving work to Kafka does not remove the notifier's database work. It moves that work to an asynchronous consumer, which still needs to write to MySQL.
MySQL headroom
Compare the estimated transaction demand with the simplified 500-commit-per-second reference:
reference commit capacity = 500 commits/second
order service demand = 66.67 commits/second
notifier demand = 66.67 commits/second
total demand = 133.33 commits/secondCalculate utilization:
database utilization = 133.33 / 500
= 0.26666
= 26.67%Calculate the remaining reference capacity:
remaining commits/second = 500 - 133.33
= 366.67The headroom factor is:
headroom factor = 500 / 133.33
= 3.75Under this simplified model, the workload uses approximately 26.67% of the reference capacity. That leaves approximately 73.33% unused.
Do not interpret the result as a guarantee that MySQL can handle 3.75 times the workload. The estimate does not account for secondary index maintenance, buffer pool misses, row and index page contention, lock waits, redo log pressure or other queries sharing the database.
Group commit may improve the practical transaction rate. Other database bottlenecks may also appear before the server reaches the simplified reference rate.
For this example, MySQL is not the first obvious bottleneck. It is still doing approximately twice the transaction work that the order service alone suggests.
Bcrypt CPU demand
Order traffic is not the only source of application CPU demand.
Your authentication endpoints use bcrypt to hash passwords and verify login attempts. Password hashing is intentionally expensive. The reference solution uses cost 12.
Assume one password verification requires approximately 250 ms of CPU time on one core. This is a hardware-dependent assumption, not a universal property of bcrypt cost 12.
Assume all 10,000 ordering users log in during the same 60-minute window. Existing users may already have valid access tokens, so this is a conservative login assumption.
Calculate the average login rate:
logins/hour = 10,000
average logins/second = 10,000 / 3,600
= 2.7778
= 2.78Apply the peak factor:
peak logins/second = 2.7778 x 4
= 11.1112
= 11.11Calculate the CPU demand:
CPU time/login = 250 ms
= 0.25 seconds
CPU seconds/second = 11.1112 x 0.25
= 2.7778
= 2.78 CPU coresPassword verification alone therefore needs approximately 2.78 CPU cores continuously at the estimated peak login rate.
On a four-core application server:
server CPU cores = 4
bcrypt CPU cores = 2.78
CPU utilization from bcrypt = 2.78 / 4
= 0.695
= 69.5%One core can theoretically perform:
logins/second/core = 1 / 0.25
= 4This leaves relatively little CPU for the API handlers, database work initiated by the API, JWT verification, serialization and background work.
Your token design matters here. Access tokens last 15 minutes. Refresh requests rotate the opaque refresh token stored in Redis. Normal authenticated order requests verify a bearer token; they do not repeat bcrypt password verification.
Keep password verification limited to login operations. Do not make every authenticated request pay the CPU cost of bcrypt.
Kafka message throughput
Each fully delivered order creates six outbox rows and six events. The relay publishes those events to the order-events topic, keyed by order ID.
At 11.11 orders per second:
messages/order = 6
Kafka messages/second = 11.1112 x 6
= 66.6672
= 66.67The outbox arrival rate is the same:
outbox rows/order = 6
outbox rows/second = 11.1112 x 6
= 66.67A Partition provides an ordered sequence of records and allows work to be distributed among consumers in a consumer group. Messages keyed by the same order ID go to the same partition, preserving their order within that partition.
The course uses three partitions for order-events. It also uses order-events.retry for failed processing and order-events.dlq for messages that fail after three attempts.
Assume an individual partition can handle roughly 10 MB per second for this workload. This is a planning assumption, not a universal Kafka limit. Actual throughput depends on message size, batching, compression, replication, acknowledgements, broker capacity and network bandwidth.
Assume each message averages 1 KB:
messages/second = 66.67
average message size = 1 KB
data rate = 66.67 x 1 KB
= 66.67 KB/secondCompare that with the assumed partition throughput:
partition capacity = 10 MB/second
estimated traffic = 0.06667 MB/second
utilization = 0.06667 / 10
= 0.006667
= 0.67%Even one partition has enough raw bandwidth under these assumptions. The three partitions provide more consumer parallelism and room for future growth. They are also the partition count already used by the course.
Consumer capacity
The notifier consumes events and writes one notification row per event. Its database transaction also records the event ID for deduplication in processed_events.
The Idempotent consumer pattern matters because Kafka delivery and retries can cause the same message to be processed more than once. The notifier must not create duplicate notification records when it sees an event again.
Assume one consumer instance takes approximately 10 ms to process one message, including the assumed database work.
processing time/message = 10 ms
= 0.01 seconds
consumer capacity = 1 / 0.01
= 100 messages/secondCalculate the minimum number of consumers required by this simplified model:
incoming messages/second = 66.67
consumer capacity = 100 messages/second
required consumers = ceil(66.67 / 100)
= 1One consumer instance is sufficient for this estimated peak. However, the topic has three partitions, so you can start with three instances in the same consumer group:
Kafka partitions = 3
consumer instances = 3
partitions per consumer = 3 / 3
= 1Assuming an even distribution, each instance receives approximately:
messages/second/consumer = 66.67 / 3
= 22.22Calculate utilization per instance:
consumer capacity = 100 messages/second
consumer demand = 22.22 messages/second
utilization = 22.22 / 100
= 22.2%Each instance has substantial headroom under the assumed workload.
A fourth consumer in this three-partition group does not receive a fourth partition. It remains idle for this topic until more partitions are available. You must consider partition count and consumer count together.
More consumers help only when the topic has enough partitions and downstream dependencies can accept the extra traffic. A slow notification provider or slow MySQL transactions can still limit the group.
Outbox relay capacity
The relay has its own polling interval and batch size. The Week 3 implementation runs inside the API process, polls unsent outbox rows in ID order, publishes to order-events using the order ID as the message key, and marks successfully published rows as sent.
The relay polls every 500 ms and takes batches of up to 100 rows. The current implementation selects rows using FOR UPDATE SKIP LOCKED and calls ProduceSync while the database transaction remains open. After successful publishing, it updates the relevant rows before committing.
This means the database transaction stays open during synchronous Kafka publishing. The relay's actual throughput depends on the time spent selecting, publishing, acknowledging, updating and committing.
Assume the following values:
relay instances = 1
batch size = 100 rows
poll interval = 500 ms
= 0.5 seconds
outbox arrival rate = 66.67 rows/secondCalculate the maximum theoretical relay capacity:
rows per batch = 100
poll interval = 0.5 seconds
relay ceiling = 100 / 0.5
= 200 rows/secondThis is an upper bound. It assumes every poll processes a full batch and ignores the time spent selecting rows, producing messages, waiting for Kafka acknowledgements, updating rows and committing the transaction.
Compare incoming rows with the theoretical ceiling:
outbox arrival rate = 66.67 rows/second
relay ceiling = 200 rows/second
utilization = 66.67 / 200
= 33.33%The simplified model gives the relay approximately three times the incoming row capacity. You still need to measure its actual throughput.
Polling delay
A newly inserted row might wait almost 500 ms before the next poll begins. If arrivals are distributed uniformly across the interval, the average polling wait is half the interval:
poll interval = 0.5 seconds
average polling wait = 0.5 / 2
= 0.25 seconds
maximum polling wait = 0.5 secondsThat is only the wait for the next poll. Complete relay delay also includes batch processing, Kafka acknowledgement time, database updates and transaction commit time.
You cannot calculate the full delay from the polling interval alone.
Outbox backlog and recovery
Assume the relay stops for ten seconds while orders continue arriving:
outbox arrival rate = 66.67 rows/second
relay downtime = 10 seconds
new backlog = 66.67 x 10
= 666.7 rows
= approximately 667 rowsCalculate how many full batches are needed to process that original backlog:
backlog = 666.67 rows
batch size = 100 rows
batches required = 666.67 / 100
= 6.67 batches
full batches required = 7
time for 7 ticks = 7 x 0.5
= 3.5 secondsThe 3.5-second estimate assumes no new rows arrive during recovery. That is not the situation in this example. New outbox rows continue arriving while the relay catches up.
Calculate the net drain rate:
relay ceiling = 200 rows/second
new arrivals = 66.67 rows/second
net drain rate = 200 - 66.67
= 133.33 rows/secondNow estimate recovery time while traffic continues:
backlog = 667 rows
net drain rate = 133.33 rows/second
drain time = 667 / 133.33
= approximately 5 secondsThe relay needs approximately five seconds to clear the backlog under these assumptions. Seven ticks describe the nominal batch slots needed for the original backlog without new arrivals. The net drain calculation accounts for ongoing traffic.
A larger batch can reduce polling overhead. It can also increase memory use and the time the database transaction remains open while publishing. A faster polling interval may reduce the wait for newly inserted rows, but it does not solve slow Kafka acknowledgements.
Storage growth
Storage grows continuously, even when the service is not experiencing a dinner peak.
Assume one 60-minute dinner window like the example occurs every day. That gives you 10,000 orders per day. This is a separate daily workload assumption, not a number that follows automatically from the registered-user count.
Estimate storage for three tables:
ordersorder_eventsoutbox
Assume the following average stored row sizes, including an allowance for ordinary row overhead:
orders row = 1 KB
order_events row = 300 bytes
outbox row = 500 bytesThese are simplified estimates. Actual storage depends on column types, variable-length data, indexes, character sets and InnoDB page organization.
Start with orders. Each order creates one order row:
orders rows/day = 10,000
orders storage/day = 10,000 x 1 KB
= 10,000 KB
= 10 MBEach completed order in this example creates six events:
events/order = 6
events/day = 10,000 x 6
= 60,000
event row size = 300 bytes
event storage/day = 60,000 x 300
= 18,000,000 bytes
= 18 MBEach order also creates six outbox rows:
outbox rows/order = 6
outbox rows/day = 10,000 x 6
= 60,000
outbox row size = 500 bytes
outbox storage/day = 60,000 x 500
= 30,000,000 bytes
= 30 MBAdd the three estimates:
orders storage/day = 10 MB
order_events storage/day = 18 MB
outbox storage/day = 30 MB
total storage/day = 10 + 18 + 30
= 58 MBUsing decimal gigabytes:
storage/day = 58 / 1,000
= 0.058 GB
monthly storage = 0.058 x 30
= 1.74 GB
yearly storage = 0.058 x 365
= 21.17 GBThe three tables grow by approximately 0.058 GB per day, or 21.17 GB per year, under this assumed workload.
These figures exclude order_lines, indexes, database logs, backups, replicas and temporary storage. They also assume published outbox rows remain stored. Deleting published rows after a retention period changes the outbox table's steady-state size.
Storage estimation helps you see how a table that looks small during development can become an operational concern after months of production traffic. Plan retention and archival policies before accumulated data becomes difficult to manage.
Concurrent work and database connections
The peak order rate also helps estimate concurrent ordering activity.
Assume an ordering session lasts an average of five minutes from beginning to completion. Apply Little's Law:
peak order arrival rate = 11.11 orders/second
average ordering session = 5 minutes
= 300 seconds
concurrent ordering sessions = 11.11 x 300
= 3,333Approximately 3,333 users are in active ordering sessions at the estimated peak.
That does not mean 3,333 HTTP requests are running simultaneously. An ordering session includes browsing restaurants, selecting items, reviewing the cart and completing checkout. Most of that time does not occupy a server connection or an active database transaction.
For example, assume an order placement request spends an average of 100 ms in the API:
request arrival rate = 11.11/second
average request time = 0.1 seconds
concurrent requests = 11.11 x 0.1
= 1.11That is approximately one to two in-flight order placement requests on average at this particular arrival rate and assumed latency.
This distinction matters when sizing the Go HTTP server and its Connection pool. A user browsing the application is not necessarily holding a database connection. Connections are needed when handlers perform database work, and the time they remain occupied affects the pool size.
Do not use registered users or active ordering sessions as a direct estimate of simultaneous database connections. Estimate database concurrency from actual query and transaction behavior.
Comparing the capacity estimates
The Friday dinner example produces the following workload:
Peak orders/minute = 666.67
Peak orders/second = 11.11
Order service transactions/order = 6
Order service transactions/second = 66.67
Notifier transactions/order = 6
Notifier transactions/second = 66.67
Total MySQL transactions/second = 133.33
Order-side row mutations/order = 21
Order-side row mutations/second = 233.33
Kafka messages/order = 6
Kafka messages/second = 66.67
Outbox rows/order = 6
Outbox rows/second = 66.67
Daily orders = 10,000
Daily storage growth = 58 MB
Yearly storage growth = 21.17 GBNow compare demand with the assumed capacity of each component.
MySQL primary
The simplified serial commit reference is 500 transactions per second. The combined order service and notifier demand is approximately 133.33 transactions per second.
That is approximately 26.67% utilization, with 366.67 commits per second remaining in the reference model. The headroom factor is approximately 3.75.
The calculation includes both order service and notifier transactions. Group commit may increase the practical transaction rate, while indexes, locks and storage behavior can impose other limits.
Authentication
At the assumed peak login rate of 11.11 per second and 250 ms of CPU time per bcrypt verification, authentication consumes approximately 2.78 CPU cores.
On a four-core application server, that is approximately 69.5% of the available CPU capacity. This is the most concerning estimate in the example.
Outbox relay
The assumed relay ceiling is 200 rows per second, compared with 66.67 incoming rows per second. That is approximately 33.33% utilization.
The 500 ms polling interval contributes an average polling wait of 250 ms and a maximum wait of 500 ms. Actual relay throughput will be lower than the theoretical ceiling because publishing and committing take time.
Kafka
The message data rate is approximately 66.67 KB per second. Against the assumed 10 MB per second per partition, one partition has sufficient raw throughput.
Three partitions provide consumer parallelism. They also limit the number of active consumers in one group to three for this topic.
Notifier consumers
Three consumer instances would each process approximately 22.22 messages per second under an even distribution.
Each has an assumed capacity of 100 messages per second, giving approximately 22.2% utilization. This leaves processing headroom, provided database operations and downstream dependencies do not become slower.
Storage
The three estimated tables grow by approximately 58 MB per day, or 21.17 GB per year.
Retention policies affect the steady-state size of the outbox table. Order and event history continue accumulating unless you archive or remove it.
Likely bottlenecks
The estimates suggest an initial bottleneck order. Treat this as a hypothesis to test, not a universal ranking.
Bcrypt authentication CPU
Bcrypt is the most likely first bottleneck in this example. At cost 12, the assumed 250 ms verification time means 11.11 logins per second consume approximately 2.78 CPU cores.
This leaves less CPU for HTTP handlers, JWT verification, serialization and background work.
Keep password verification out of the normal order placement path. Use access tokens for authenticated requests and apply appropriate rate limits to authentication endpoints. If login traffic increases, consider additional CPU capacity or stricter admission control for authentication requests.
MySQL write contention
The simplified commit calculation suggests adequate capacity, but real database performance can deteriorate because of indexes, locks and storage behavior.
Remember that MySQL handles approximately 133.33 transactions per second in this example, including notifier transactions.
If MySQL becomes the bottleneck, inspect slow queries and transaction durations. Check the indexes used by order lookups, notifier processing and outbox polling. Review connection pool settings and transaction timeouts.
Do not increase the number of API instances without checking the database connection pool. More application instances can create more simultaneous database connections and increase contention.
Outbox relay delay
The relay has substantial theoretical capacity in this example, but polling and synchronous publishing can introduce delay.
If notifications consistently arrive late, measure the age of the oldest unpublished outbox row. Also record how long each batch takes to publish and commit.
Increasing the batch size may help when polling overhead is the limiting factor. Increasing polling frequency may reduce the delay for newly created rows. Neither change helps when Kafka publishing is blocked or the relay spends most of its time waiting for acknowledgements.
The relay holds its database transaction open while publishing. Long publishing delays can increase lock duration and affect other database operations. Track failed publishes and the age of rows that have repeatedly failed. A failed publish must not silently remove an outbox row.
Kafka and consumer processing
Kafka throughput is unlikely to be the first bottleneck at 66.67 messages per second with the assumed message size.
The consumers may become the limiting component if notification processing takes longer than expected. External notification services can introduce their own rate limits, network delays and failures.
Monitor Consumer lag, the gap between the newest Kafka offset and the consumer's committed offset. For example, if a partition has reached offset 10,000 and its consumer has committed offset 9,800, the difference is 200 messages.
Growing lag means messages are accumulating faster than the consumer group is processing them. For the notifier, this usually means a longer delay between an order event and its corresponding notification.
A temporary lag increase during a traffic burst is not automatically a failure. Lag that continues growing after traffic returns to normal is a stronger indication that consumer capacity is insufficient.
Check whether the limiting factor is message processing, notification-provider latency, retry behavior or insufficient partitions before adding more consumer instances.
Storage and retention
Storage is not necessarily the first bottleneck during a dinner peak, but it accumulates continuously.
At 58 MB per day, the three estimated tables grow by approximately 21.17 GB per year. Decide how long to retain published outbox records, whether old events need archival and how long operational data must remain directly available.
Deleting historical data without considering audit requirements or debugging needs can create problems. Retention should be a deliberate policy rather than an emergency response to a full database disk.
Measuring the real system
Every figure in this lesson is an assumption to verify. Commit latency, row sizes, message sizes, partition throughput, consumer processing time, relay throughput and bcrypt CPU time all depend on the actual environment.
Week 6 will measure the system rather than relying on these estimates. Start by recording the assumptions you used, then replace them with observed values.
Order placement load
Use k6 to generate realistic traffic against POST /v1/orders. Start below the estimated peak and increase the request rate gradually.
Measure:
- Requests per second and successful orders per second.
- HTTP response latency, especially p95 and p99.
- HTTP error rates.
- Database transaction duration.
- Connection pool wait time.
- CPU and memory usage.
Use realistic order payloads with three lines and valid access tokens. Do not perform a new login for every order unless you are deliberately measuring authentication capacity. Otherwise, bcrypt may dominate the results and hide the behavior of the order endpoint.
Also test duplicate requests with the same Idempotency-Key. A client retry must not create another order when the original request has already been accepted.
MySQL queries and transactions
Use EXPLAIN to inspect the queries involved in order lookup, state transitions, notifier processing and outbox polling.
Check whether the queries use the intended indexes. Measure actual transaction duration and observe lock waits under concurrent load.
The important comparison is not only the number of rows written. It is how long MySQL spends completing the order service and notifier transactions associated with each order.
A query that scans a large table or waits on a lock can reduce throughput far below the simplified commit estimate.
Redis operations
Authentication and rate limiting also use Redis. Use redis-benchmark for an initial view of command throughput, but do not treat a synthetic benchmark as an application benchmark.
Measure the actual operations used by the application, including token lookup, refresh token rotation and rate-limit counter updates. Check connection pool waits and command latency.
The Idempotency-Key claim also uses Redis, so include that operation when measuring order placement under retry-heavy traffic.
Outbox and Kafka metrics
For the relay, record:
- Rows fetched per poll.
- Rows successfully published per second.
- Batch processing duration.
- Time spent in
ProduceSync. - Database transaction duration.
- Failed publish count.
- Age of the oldest unpublished row.
For Kafka consumers, record:
- Messages processed per second.
- Consumer lag per partition.
- Processing duration.
- Retry count.
- Dead-letter topic growth.
Measure the delay from outbox row creation to successful completion of notification processing. This gives you an end-to-end view instead of measuring Kafka throughput in isolation.
Updated assumptions
When measurements become available, recalculate the model.
For example, suppose MySQL commits take 5 ms instead of 2 ms. The simplified serial reference becomes:
commit latency = 5 ms
= 0.005 seconds
serial commit reference = 1 / 0.005
= 200 commits/second
estimated total demand = 133.33 commits/second
utilization = 133.33 / 200
= 66.67%The same workload now uses approximately 66.67% of the simplified reference capacity rather than 26.67%.
Suppose each consumer message takes 50 ms instead of 10 ms:
processing time/message = 50 ms
= 0.05 seconds
consumer capacity = 1 / 0.05
= 20 messages/second
incoming messages/second = 66.67
required consumers = ceil(66.67 / 20)
= 4However, the topic has only three partitions. At most three consumers in this group can actively process this topic at the same time.
Calculate the group's combined capacity:
consumer instances = 3
capacity/consumer = 20 messages/second
group capacity = 3 x 20
= 60 messages/second
incoming rate = 66.67 messages/second
lag growth = 66.67 - 60
= 6.67 messages/secondThe consumer group cannot keep up. Under sustained peak traffic, lag grows by approximately 6.67 messages per second.
You would need to improve processing time, increase the partition count or reduce the workload before adding more consumers could solve the problem.
Now suppose the average Kafka message size increases from 1 KB to 10 KB:
data rate = 66.67 x 10 KB
= 666.7 KB/secondThat is still below the assumed single-partition bandwidth, but it changes network and storage requirements.
The point of an estimate is not to defend its original numbers. Update the model when measurements provide better information.
From estimates to measurements
The Friday dinner example produces approximately 11.11 orders per second, 133.33 MySQL transactions per second and 66.67 Kafka messages per second. The simplified model suggests that bcrypt authentication CPU is the most immediate concern, while MySQL, the relay and the notifier have more estimated headroom.
These results describe the workload implied by the assumptions. They do not prove that a particular machine can sustain it.
Use the estimates to decide what to measure first. Then compare observed throughput, latency, resource use and backlog growth against the model. Week 6 applies that approach with load tests, metrics and profiling.
Check your understanding
A service has 200,000 registered users. Five percent place an order during a 60-minute window. The busiest minute is four times the average minute. Approximately how many orders arrive during the busiest minute?
References
Everything above is explained on this page; these are where it comes from (Go, MySQL 8.4, Kafka (Redpanda)).
Order service capacity
1 items
- 3.20Capacity estimationnot completed
Up next · Module 8 · 4 items · about 3 h 15 min