Capacity: how many users can this rate limiter serve?

Back-of-the-envelope capacity estimation with the full calculation: requests per second, peak load, Little's Law, Redis throughput and memory, and how many API instances and Redis primaries the Week 1 limiter needs for a million registered users.

Learning outcomes

  • Convert a user count into average and peak requests per second and say what the peak factor means.
  • Use Little's Law to turn a request rate and a latency into the number of requests in flight.
  • Estimate Redis commands per second and key memory for the Redis fixed-window limiter.
  • Work out how many API instances and Redis primaries a target load needs, and state the assumptions.

You have built a rate limiter that works. It accepts requests, counts them, rejects requests that exceed a limit, and uses Redis to share rate-limit state across API instances. You have also configured a timeout so a slow Redis connection does not leave your HTTP handlers waiting indefinitely.

But there is another question you need to answer before putting this system into production:

How many users can this rate limiter actually serve?

Saying that your rate limiter works for one request does not tell you whether it works for 10,000 requests per second. Passing unit tests does not tell you whether Redis can handle the traffic generated by 100,000 active users. Running the application locally does not tell you how many API instances you need when traffic increases.

You need a way to estimate capacity before running a load test.

This is called Capacity estimation. It is the process of approximating how much traffic a system can handle using its expected workload, resource consumption, and infrastructure limits.

You do not need an expensive monitoring platform or a production environment to make your first estimate. You need a few assumptions, some arithmetic, and an understanding of where your application spends its time.

The estimates will not be exact. Their purpose is to give you a reasonable starting point, identify likely bottlenecks, and help you decide what to measure.

In this lesson, you will estimate the capacity of the Week 1 rate limiter using the same components you have already implemented:

  • A Go HTTP API using chi.
  • An HTTP middleware that applies a fixed-window rate limiter.
  • Redis as the shared rate-limit store.
  • A Redis transaction that executes INCR and EXPIRE NX.
  • An in-memory FixedWindow fallback when Redis times out.
  • Multiple Go API instances running behind a load balancer.

By the end, you should be able to explain how many active users this system can accommodate, how many API instances it needs, and whether one Redis primary is sufficient.

Start with requests per second

Requests per second (RPS) (RPS) is the number of HTTP requests a server receives or processes in one second.

For example:

  • 100 requests in one second means 100 RPS.
  • 1,000 requests in one second means 1,000 RPS.
  • 10,000 requests in one second means 10,000 RPS.

RPS is a useful measure because infrastructure capacity is usually discussed in terms of how much work a system can process over time.

Consider a food-delivery application.

A registered user might open the application, browse restaurants, view menus, add items to a cart, and place an order. Each of these actions can generate one or more HTTP requests.

A user does not necessarily generate requests continuously. They might make several requests in a short period and then stop interacting with the application.

Therefore, you should distinguish between registered users and active users.

A registered user is someone who has an account. An active user is someone who is actually generating traffic during the period you are measuring.

If an application has one million registered users, it does not follow that one million users are making requests simultaneously.

For capacity planning, you need to estimate how many users are active and how frequently they make requests.

Average load and peak load

Average load is the average number of requests received per second over a specified period.

Peak load is the higher request rate that occurs during particularly busy periods.

For a food-delivery application, traffic might be relatively low in the afternoon and much higher around lunch and dinner.

If you calculate capacity using only average traffic, you can underestimate the resources required during busy periods.

A useful planning assumption is the Peak factor, which is the ratio of peak traffic to average traffic over a chosen measurement window.

For example, a peak factor of 3 means that the system experiences three times its average request rate during its busiest period.

The relationship is:

peak RPS = average RPS x peak factor

Suppose your application receives an average of 2,000 requests per second and you expect a peak factor of 3.

average RPS = 2,000
peak factor = 3

peak RPS = 2,000 x 3
peak RPS = 6,000

Your infrastructure must be able to handle approximately 6,000 requests per second if you want to accommodate that expected peak.

The peak factor is not a universal constant. It depends on your application's traffic patterns. You might estimate it initially, but you should eventually calculate it from real traffic measurements.

Little's Law and concurrent requests

A server does not necessarily finish a request immediately after receiving it. Requests spend time executing application code, waiting for Redis, reading from a database, or waiting for another service.

You need to understand how many requests are in progress at the same time.

Little's Law is a relationship between arrival rate, time spent in a system, and the average number of items inside that system.

For an HTTP server, you can use this simplified form:

concurrency = arrival rate x latency

Where:

  • Concurrency is the average number of requests being processed or waiting inside the system.
  • Arrival rate is the number of requests arriving per second.
  • Latency is the average time each request spends in the system, measured in seconds.

For example, suppose your API receives 1,000 requests per second and each request takes 50 milliseconds.

Convert milliseconds to seconds:

50 milliseconds = 0.05 seconds

Apply Little's Law:

concurrency = 1,000 x 0.05
concurrency = 50

On average, approximately 50 requests are in progress simultaneously.

Now suppose traffic increases to 10,000 requests per second while latency remains 50 milliseconds.

concurrency = 10,000 x 0.05
concurrency = 500

You now have approximately 500 concurrent requests.

This matters because your server must have enough resources to handle those requests without exhausting its CPU, memory, connection pools, or other resources.

Little's Law also explains why a service that becomes slower can experience increasing concurrency even if its incoming RPS does not change.

For example, if Redis latency increases from 5 milliseconds to 100 milliseconds, more HTTP handlers remain occupied waiting for Redis.

The request rate has not changed, but the number of requests in progress has increased.

CPU-bound versus I/O-bound handlers

To estimate API capacity, you need to understand what consumes resources while a handler processes a request.

A CPU-bound handler spends most of its time executing instructions on the processor.

Examples include:

  • Computing a large response.
  • Performing expensive serialization.
  • Running cryptographic operations.
  • Processing large amounts of data in memory.

An I/O-bound handler spends much of its time waiting for an external operation to finish.

Examples include:

  • Waiting for a Redis response.
  • Querying MySQL.
  • Calling another HTTP service.
  • Reading from or writing to a network connection.

Your Week 1 rate-limiting middleware is largely I/O-bound when Redis is enabled.

The middleware performs a Redis operation, waits for the result, and then decides whether to allow the HTTP request.

While the Go handler waits for Redis, its goroutine is not continuously consuming a CPU core.

This distinction matters because you cannot estimate API capacity using only the number of goroutines or the number of concurrent requests.

A server with two CPU cores can support many more than two concurrent I/O-bound requests. The operating system and Go runtime can schedule other work while individual goroutines wait for network operations.

However, a CPU-bound workload is constrained by available processor time.

For an initial estimate, you can calculate the theoretical CPU capacity of an instance using the CPU time consumed by each request.

Suppose one request consumes 2 milliseconds of CPU time.

A single CPU core provides approximately 1,000 milliseconds of CPU time per second.

CPU capacity per core = 1,000 ms/second

CPU time per request = 2 ms

requests per second per core = 1,000 / 2
requests per second per core = 500

A two-core instance theoretically supports:

requests per second = 500 x 2
requests per second = 1,000

This assumes that all available CPU time can be used for request processing.

In production, you should not plan to run continuously at 100% CPU utilization. You need room for garbage collection, operating system work, background goroutines, traffic bursts, and unexpected processing costs.

If you reserve 40% of CPU capacity, you can use approximately 60% for normal request processing.

usable CPU capacity = 2 x 1,000 x 0.60
usable CPU capacity = 1,200 ms/second

requests per second = 1,200 / 2
requests per second = 600

Therefore, our planning estimate is 600 requests per second per two-vCPU API instance.

This is an assumption about CPU consumption, not a guaranteed throughput figure.

Your actual handler might consume more or less CPU time depending on serialization, logging, authentication, middleware, and the work performed by the endpoint.

Estimating Redis throughput

Redis is the shared state store in your rate limiter.

Every request that passes through the Redis-backed fixed-window middleware needs to update its rate-limit counter.

Your implementation uses a Redis transaction to execute two operations:

  1. INCR increments the counter for the current window.
  2. EXPIRE NX sets the expiration if the key does not already have an expiration.

These operations are sent together using the Redis transaction pipeline.

Redis is extremely fast for many workloads because it operates primarily on data in memory. However, its throughput is not unlimited.

A single Redis primary is mostly single-threaded for command execution. It can use additional threads for certain networking and background tasks, but you should not assume that adding CPU cores increases command execution throughput linearly.

For a rough capacity estimate, modern commodity hardware might process tens of thousands to hundreds of thousands of simple Redis operations per second.

This is an order-of-magnitude estimate, not a performance guarantee. The actual result depends on the processor, memory, Redis version, network, command mix, data structures, persistence settings, and workload.

For planning, you might initially use 100,000 Redis command executions per second as an illustrative budget.

You must measure the actual machine using redis-benchmark before treating that number as useful for a deployment decision.

There is an important distinction between Redis operations and Redis round trips.

An operation is a command that Redis executes.

A round trip is the network exchange required for your application to send work to Redis and receive its response.

Your transaction contains two rate-limit operations:

INCR
EXPIRE NX

The transaction also has MULTI and EXEC control commands.

Therefore, each request involves:

rate-limit operations per request = 2
transaction control commands per request = 2

total Redis command invocations = 4

The two rate-limit operations are executed within one transaction.

The application sends the transaction and waits for its result in one network round trip. It does not send INCR, wait for its response, and then send EXPIRE NX in a second round trip.

This is why Redis transactions and Redis pipelines are useful for reducing network overhead while keeping the counter update and expiration setup together.

The distinction becomes important when you calculate Redis capacity.

If your application receives 10,000 requests per second:

rate-limit operations per second = 10,000 x 2
rate-limit operations per second = 20,000

transaction control commands per second = 10,000 x 2
transaction control commands per second = 20,000

total command invocations per second = 40,000

transaction round trips per second = 10,000

Your Redis primary receives 40,000 command invocations per second, but the application performs only 10,000 transaction round trips per second.

The actual execution cost of the transaction is not necessarily equivalent to four independent simple commands. Redis transaction processing and network overhead must also be measured.

Memory per rate-limit key

Redis throughput is not the only constraint. You also need to estimate how much memory the rate limiter consumes.

A Fixed-window counter stores a counter for a particular identity and time window.

For example, a rate-limit key might represent one user's request count during a particular minute.

Conceptually, it contains:

  • A key name identifying the user and window.
  • A counter value.
  • An expiration time.
  • Redis internal metadata.

The actual memory consumed is larger than the length of the key and the counter value.

Redis uses internal data structures to manage keys, values, dictionaries, expiration metadata, and memory allocation. There is also allocator overhead and possible fragmentation.

For a first estimate, assume each rate-limit key consumes 200 bytes in total, including the key, value, Redis metadata, and allocation overhead.

This is an illustrative assumption. You should measure actual usage with Redis memory inspection commands such as MEMORY USAGE.

The memory calculation is straightforward:

memory = number of active keys x bytes per key

Suppose you have 100,000 active keys.

active keys = 100,000
memory per key = 200 bytes

memory = 100,000 x 200
memory = 20,000,000 bytes
memory = approximately 20 MB

If you have one million active keys:

memory = 1,000,000 x 200
memory = 200,000,000 bytes
memory = approximately 200 MB

Expiration is important here.

Your Redis implementation sets a TTL on each rate-limit key. Once the window expires, Redis can remove the key, preventing old counters from accumulating indefinitely.

For the calculation, assume one rate-limit key per active user per ten-minute window. Also assume that all active users have generated at least one request during that window.

This means the number of keys is approximately the number of users who have generated requests during the window, not the number of HTTP requests themselves.

If a user makes 30 requests during the same window, those requests update the same key rather than creating 30 separate keys.

Be careful when the limiter has multiple scopes. If you maintain separate counters for users, IP addresses, endpoints, or other identities, each scope can create additional keys.

For example, three independent rate-limit scopes might require approximately three times the key memory.

Network round trips are a real cost

You have now estimated CPU consumption, Redis throughput, and memory. There is another cost that is easy to overlook: network communication.

A network round trip is the time required for a request to travel from your application to Redis and for the response to return.

Even when Redis executes commands very quickly, the application must still communicate with it.

Consider two implementations.

The first sends two separate Redis commands and waits for each response:

INCR request
wait for response

EXPIRE request
wait for response

This requires two sequential network round trips.

The second uses a transaction pipeline:

MULTI
INCR
EXPIRE NX
EXEC
wait for transaction response

This sends the transaction together and waits for the result in one round trip.

The second implementation reduces network waiting time.

Suppose the application and Redis are on the same private network and the round-trip latency is 1 millisecond.

At 15,000 requests per second, the application initiates approximately 15,000 transaction round trips per second.

The aggregate waiting time across all requests is substantial, even though each individual request waits only a short time.

Little's Law helps quantify the concurrency required to support that waiting.

arrival rate = 15,000 requests/second
Redis round-trip latency = 0.001 seconds

average requests waiting on Redis
= 15,000 x 0.001

= 15 concurrent requests

This is the average number of requests waiting on Redis, assuming the stated latency remains stable.

If round-trip latency rises to 10 milliseconds:

average requests waiting on Redis
= 15,000 x 0.010

= 150 concurrent requests

The number of waiting requests increases tenfold.

This does not necessarily mean that the Redis server is executing commands more slowly. Network congestion, connection pool limits, scheduling delays, and server saturation can all contribute to increased latency.

Your redis-pipeline implementation reduces the number of sequential waits, but it does not eliminate network communication.

The practical lesson is that you must measure both Redis command throughput and application-to-Redis latency.

Worked example: capacity for one million registered users

Now put the concepts together.

We will estimate the capacity of the Week 1 rate limiter for a food-delivery application with one million registered users.

We will explicitly state every assumption so that you can change the numbers later.

Step 1: Estimate the active users

Assume the application has 1,000,000 registered users.

During a busy evening, assume 10% of registered users are active.

registered users = 1,000,000
active percentage = 10%

active users = 1,000,000 x 0.10
active users = 100,000

We therefore expect 100,000 active users during the busy evening.

For this example, assume all 100,000 users make requests within the measurement window.

Step 2: Calculate average RPS

Assume each active user makes approximately 30 requests in a ten-minute window.

Convert ten minutes into seconds:

window = 10 minutes
window = 10 x 60
window = 600 seconds

Calculate the total number of requests:

active users = 100,000
requests per user = 30

total requests = 100,000 x 30
total requests = 3,000,000

Now divide the total requests by the window duration:

total requests = 3,000,000
window duration = 600 seconds

average RPS = 3,000,000 / 600
average RPS = 5,000

The application receives an average of 5,000 requests per second during this ten-minute window.

Step 3: Calculate peak RPS

Assume a peak factor of 3.

This means the busiest period experiences three times the average request rate.

average RPS = 5,000
peak factor = 3

peak RPS = 5,000 x 3
peak RPS = 15,000

Your system should therefore be planned to handle approximately 15,000 requests per second.

Notice that the total number of requests has not changed. The peak factor describes how those requests are distributed over time.

Step 4: Calculate Redis command throughput

Every request passes through the Redis-backed fixed-window middleware.

Each request executes:

  • One INCR operation.
  • One EXPIRE NX operation.
  • One MULTI command.
  • One EXEC command.

The transaction pipeline sends the operations together, requiring one network round trip per request.

At peak traffic:

peak RPS = 15,000

INCR operations per second = 15,000
EXPIRE NX operations per second = 15,000

rate-limit operations per second
= 15,000 + 15,000
= 30,000

Include the transaction control commands:

MULTI commands per second = 15,000
EXEC commands per second = 15,000

total Redis command invocations
= 30,000 + 15,000 + 15,000
= 60,000 commands/second

And the network round trips:

transactions per second = 15,000

round trips per request = 1

Redis round trips per second
= 15,000 x 1
= 15,000

We are estimating 60,000 Redis command invocations per second and 15,000 transaction round trips per second.

Now compare this with our illustrative Redis planning budget of 100,000 command invocations per second.

estimated Redis budget = 100,000 commands/second
estimated peak demand = 60,000 commands/second

remaining capacity = 100,000 - 60,000
remaining capacity = 40,000 commands/second

utilization = 60,000 / 100,000
utilization = 60%

Under these assumptions, one Redis primary is sufficient.

It has approximately 40% of its estimated command capacity remaining.

However, this conclusion is valid only if the actual Redis instance can sustain the assumed throughput with acceptable latency.

Transaction overhead, persistence, network conditions, and other Redis workloads can reduce the available capacity.

You must benchmark the actual workload rather than assume that a result from a simple redis-benchmark command will match your application.

Step 5: Calculate Redis memory requirements

We assumed one key per active user per ten-minute window.

All 100,000 active users are assumed to have generated at least one request during the window.

Therefore:

active users = 100,000
keys per user = 1

active rate-limit keys = 100,000

Assume each key consumes 200 bytes, including its key name, value, metadata, expiration information, and allocator overhead.

Calculate the memory:

memory per key = 200 bytes
active keys = 100,000

total memory = 100,000 x 200
total memory = 20,000,000 bytes
total memory = approximately 20 MB

The rate limiter needs approximately 20 MB for these active keys under our assumptions.

This is a relatively small amount of memory for a modern Redis instance.

However, you should not allocate only 20 MB of Redis memory. The instance also needs memory for other application data, internal structures, replication buffers if configured, and operational overhead.

You should also account for the fact that key count depends on the number of identities and scopes being rate-limited.

Step 6: Calculate the number of API instances

Now estimate how many Go API instances are required.

Assume each API instance has:

  • 2 vCPUs.
  • 2 milliseconds of CPU time per HTTP request.
  • A target CPU utilization of 60%.

We calculated earlier that one such instance can process approximately 600 requests per second within this CPU budget.

Let's show the complete calculation again.

CPU cores = 2
CPU time available per core = 1,000 ms/second

total CPU time = 2 x 1,000
total CPU time = 2,000 ms/second

target utilization = 60%

usable CPU time = 2,000 x 0.60
usable CPU time = 1,200 ms/second

CPU time per request = 2 ms

requests per second per instance
= 1,200 / 2
= 600

Each instance can therefore handle an estimated 600 requests per second.

Our peak traffic is 15,000 RPS.

Calculate the required number of instances:

peak RPS = 15,000
capacity per instance = 600

required instances = 15,000 / 600
required instances = 25

You need at least 25 API instances to handle the estimated peak under these assumptions.

However, running exactly 25 instances leaves no additional capacity under this planning model.

You should leave room for traffic growth and temporary increases in CPU consumption.

Assume you deploy 30 instances instead.

deployed instances = 30
capacity per instance = 600

total API capacity = 30 x 600
total API capacity = 18,000 RPS

expected peak = 15,000 RPS

spare capacity = 18,000 - 15,000
spare capacity = 3,000 RPS

You have provisioned 20% more capacity than the expected peak demand.

The remaining capacity is 16.7% of the total provisioned throughput.

This gives you some room for unexpected traffic increases and workload variation.

Step 7: Calculate concurrent requests

We have estimated the request rate and API instance count. Now estimate how many requests will be in progress simultaneously.

Assume an average end-to-end HTTP handler latency of 50 milliseconds at peak load.

This includes application processing and waiting for Redis, but it is an illustrative latency assumption that must be measured.

Convert latency into seconds:

handler latency = 50 ms
handler latency = 0.05 seconds

Apply Little's Law:

peak RPS = 15,000
handler latency = 0.05 seconds

concurrent requests = 15,000 x 0.05
concurrent requests = 750

Approximately 750 requests will be in progress across the API fleet at peak traffic.

With 30 API instances:

concurrent requests = 750
API instances = 30

average concurrent requests per instance
= 750 / 30
= 25

Each API instance handles approximately 25 concurrent requests on average at this latency and traffic level.

This is not a limit on the number of goroutines the server can create. It is an estimate of the average number of requests in progress.

If latency increases, concurrency increases even if RPS remains unchanged.

For example, at 100 milliseconds of latency:

concurrent requests = 15,000 x 0.1
concurrent requests = 1,500

The number of concurrent requests doubles.

This is why monitoring latency is just as important as monitoring throughput.

Step 8: Make the capacity decision

Bring the estimates together.

registered users = 1,000,000
active users = 100,000

average traffic = 5,000 RPS
peak traffic = 15,000 RPS

Redis operations = 30,000/second
Redis command invocations = 60,000/second
Redis round trips = 15,000/second

Redis keys = 100,000
estimated key memory = 20 MB

API instances required = 25
API instances deployed = 30

provisioned API capacity = 18,000 RPS
peak concurrency = 750 requests

Our illustrative Redis primary has a planning budget of 100,000 command invocations per second. The estimated peak demand is 60,000, leaving 40% of that budget unused.

The API fleet has 30 instances with an estimated combined capacity of 18,000 RPS, leaving 3,000 RPS above the expected peak.

The answer: approximately 100,000 active users per Redis primary at this traffic pattern, with 30 two-vCPU Go API instances deployed. This corresponds to 15,000 peak RPS, 750 concurrent requests, and approximately 20 MB of active rate-limit key memory. The Redis primary retains an estimated 40% command-throughput headroom, while the API fleet has 20% capacity above expected peak demand.

This is a planning estimate, not a production capacity guarantee.

It also assumes the Redis primary, API network, connection pools, and load balancer can all sustain their respective workloads.

What breaks first

The calculation suggests that one Redis primary is sufficient. However, a capacity estimate is useful only when you understand what happens as the workload grows.

For this workload, the likely bottlenecks are:

Redis command execution and latency

Redis is a shared dependency for every request passing through the distributed rate limiter.

As traffic increases, Redis must execute more transaction commands and process more network requests.

If its command-processing capacity is exceeded, Redis response latency can increase. Go handlers then spend more time waiting for Redis.

The first thing to investigate is whether Redis CPU utilization, command latency, network throughput, or connection saturation is increasing.

Adding Redis replicas does not solve this write bottleneck. Replicas can help with read workloads, but your INCR and EXPIRE NX operations must still be handled by the primary.

If one primary can no longer handle the write workload, you can consider sharding rate-limit keys across multiple Redis nodes.

For example, you could distribute users across several Redis primaries using a consistent hashing strategy.

Each primary then handles only a portion of the total keys and traffic.

This introduces additional operational complexity, including key distribution, routing, failover, and changes to how you manage rate-limit state.

API CPU consumption

If request processing requires more CPU than expected, your API instances will reach their CPU limits sooner.

You might discover that the actual cost is 4 milliseconds per request instead of 2 milliseconds.

Under the same 60% CPU utilization assumption:

usable CPU time = 1,200 ms/second
CPU time per request = 4 ms

capacity per instance = 1,200 / 4
capacity per instance = 300 RPS

Your required API instance count would double:

required instances = 15,000 / 300
required instances = 50

This is why measuring actual CPU consumption per request matters.

Network and connection limits

Your API instances need enough Redis connections to handle concurrent transactions.

If the connection pool is too small, requests may wait for an available connection even when Redis itself has spare processing capacity.

If the network becomes saturated or round-trip latency increases, more handlers remain occupied waiting for Redis.

Measure connection pool wait time, connection utilization, and Redis round-trip latency.

Memory growth

If your rate-limit keys do not expire correctly, Redis memory consumption can grow over time.

The fixed-window implementation relies on expiration to remove old counters.

Increasing the rate-limit window also increases how long keys remain active. A larger window can increase the number of retained keys, depending on how you construct the keys and whether multiple windows coexist.

Before increasing the window size, calculate the additional memory requirements.

Local fallback limitations

Your middleware has a fail-open path.

When Redis exceeds the configured 50 ms timeout, the middleware falls back to an in-memory FixedWindow limiter.

This changes the failure picture.

If Redis becomes unavailable, the application can continue serving requests instead of blocking indefinitely while waiting for the shared rate-limit store.

However, each API instance now maintains its own independent counters.

Suppose you have 30 API instances. A user might receive the full local rate limit on each instance rather than one shared limit across the fleet.

The effective limit can therefore be substantially higher than the configured distributed limit.

Fail-open improves availability, but it weakens rate-limit enforcement during Redis failures.

It is also not a guarantee that the application can survive every Redis outage. CPU, memory, network, and downstream services can still become overloaded.

Your next steps depend on the bottleneck:

  • If Redis write throughput is the problem, shard keys across Redis primaries. Adding read replicas will not solve it.
  • If Redis memory is the problem, inspect key cardinality, TTL behavior, and the number of rate-limit scopes.
  • If API CPU is the problem, optimize handler work or increase the number of API instances.
  • If connection waiting is the problem, investigate connection pool sizing and network latency.
  • If traffic bursts are the problem, consider local pre-limits to reject obviously excessive traffic before sending every request to Redis.

A local pre-limit can reduce Redis traffic, but it must be designed carefully. Independent local counters cannot enforce an exact global limit across multiple API instances.

Increasing the rate-limit window is another possible design change, but it is not a general solution to throughput problems. It changes rate-limit behavior and may increase key retention.

The important point is to identify the actual bottleneck before changing the architecture.

Check the estimate

Everything in the worked example is an assumption.

The 2 milliseconds of CPU per request, 50 milliseconds of handler latency, 200 bytes per Redis key, and 100,000 Redis commands per second are not guaranteed properties of Go or Redis.

They are starting values for an engineering estimate.

In Week 6, you will use load testing to compare these estimates against actual measurements.

You will use k6 to generate HTTP traffic against the Go API.

A load test can measure:

  • Requests per second.
  • Average and percentile response latency.
  • Error rates.
  • HTTP 429 responses.
  • API CPU and memory utilization.
  • Behavior as concurrency increases.

You will also use redis-benchmark to measure Redis performance independently.

For example, you can benchmark Redis command execution under different concurrency levels and compare the results with your estimated Redis workload.

However, a simple benchmark is not identical to your application's workload.

Your application uses transactions containing INCR and EXPIRE NX, communicates over a network, and operates with a particular key distribution and expiration pattern.

Therefore, you should also measure the actual transaction path used by your middleware.

A useful testing sequence is:

  1. Benchmark Redis independently to understand its approximate command throughput.
  2. Load-test the Go API without Redis to estimate the application's processing capacity.
  3. Enable the Redis-backed middleware and repeat the test.
  4. Compare CPU utilization, Redis latency, request latency, and throughput.
  5. Increase traffic gradually until latency or error rates become unacceptable.
  6. Test Redis timeouts and failures to verify that the fail-open behavior works as expected.

Do not look only at average latency.

A service can have acceptable average latency while a significant number of requests experience very slow responses.

Pay attention to p95 and p99 latency. These represent the latency below which 95% and 99% of requests complete, respectively.

You should also observe what happens when the load increases beyond your estimated capacity.

Does Redis latency increase first? Does API CPU reach its target utilization? Do connection pools become saturated? Does the fallback activate?

These observations tell you whether your original assumptions were reasonable.

Summary

Capacity estimation helps you reason about how much traffic your application can handle before deploying it.

The main ideas are:

  • RPS measures how many HTTP requests arrive or are processed per second.
  • Average traffic and peak traffic are different. A peak factor estimates how much higher peak traffic is than average traffic.
  • Little's Law relates request rate, latency, and concurrency.
  • CPU-bound handlers consume processor time, while I/O-bound handlers spend much of their time waiting for external operations.
  • Redis throughput is limited and must be benchmarked on the actual hardware and workload.
  • Redis memory consumption depends on the number of active keys and the memory consumed by each key, including internal overhead.
  • Network round trips contribute to request latency even when Redis command execution is fast.
  • A transaction pipeline reduces sequential network waiting, but it does not eliminate Redis command execution or network costs.
  • Redis replicas do not increase the write capacity of a single primary.
  • Fail-open improves availability during Redis failures but weakens globally consistent rate-limit enforcement.

In the worked example, one million registered users generate an estimated 15,000 peak requests per second when 10% are active and the peak factor is 3.

Under the stated assumptions, that workload requires approximately 60,000 Redis command invocations per second, 20 MB of rate-limit key memory, and 25 API instances at the assumed per-instance capacity.

Deploying 30 API instances provides additional API capacity, while one Redis primary retains an estimated 40% command-throughput headroom.

These estimates must be verified through benchmarking and load testing.

Knowledge assessment

Question 1 of 5

An application receives an average of 2,000 requests per second. Its peak factor is 4. What is its estimated peak RPS?

Pick an answer, then say how sure you are.

Practical applications

  • Week 5: Estimate rider location updates per second and the number of concurrent connections required to support location tracking.
  • Week 6: Use k6 and redis-benchmark to load-test your services, measure actual throughput and latency, and compare production-like measurements against the capacity estimates developed in this lesson.

References

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

Finished Lesson 1.25?

Capacity estimation and user load

1 items

  • 1.25Capacity: how many users can this rate limiter serve?not completed

Optional extensions

Up next · Module 9 · 5 items · about 4 h 45 min

Start module 9