Estimating mobile API capacity

Estimate how Week 4 app behaviour translates into Go API request rates so you can set realistic load-test targets before measuring the backend.

Learning outcomes

  • Estimate daily API requests from installs, active users, sessions and requests per session.
  • Calculate how client caching, pagination and debouncing change the number of requests reaching the API.
  • Estimate peak RPS, response bandwidth, polling traffic and token refresh bursts.
  • Use Little's Law and a planning capacity to estimate in-flight requests and concurrent users.
  • Identify which backend resources to measure when validating your estimates.

A customer opening the restaurant list does not generate the same workload as a customer following an unfinished order. One screen might reuse cached data, while another sends a request every ten seconds. When thousands of customers use the app together, these differences determine how much traffic your Go API receives.

You have built the client features in Week 4. Now you need to estimate their combined workload before you run the load tests in Week 6. The goal is not to predict an exact production capacity. It is to build a defensible estimate, identify the assumptions behind it, and decide what to measure.

The client request model

Capacity estimation means estimating the resources required to handle a particular workload. You start with user activity and the operations performed by the app. You then translate that activity into API requests, bandwidth and concurrent work.

The Week 4 app has several sources of API traffic:

  • Restaurant browsing sends requests for restaurant list pages.
  • Menu browsing retrieves menu data.
  • The configurator sends quote requests when a customer changes their selections.
  • Checkout creates an order.
  • Order history retrieves previous orders and polls an unfinished order's detail.
  • Authentication sends login and token refresh requests.
  • TanStack Query can refetch queries when the app regains focus or network connectivity returns.

These operations do not all behave in the same way. Some reads can use cached data. Some operations are debounced. Some requests are mutations that must reach the API. Others repeat at a fixed interval.

You should model each source before adding the numbers together.

Restaurant browsing

The restaurant list uses keyset pagination. Each page requests 20 restaurants with limit=20.

The seed contains 50 restaurants. A customer who scrolls through all of them can therefore request three pages:

PageRestaurants returned
First20
Second20
Third10

Loading the first page sends one request. Scrolling far enough to load the remaining restaurants can send two more requests.

The restaurant list query has a staleTime of 60 seconds. When the customer returns to the list while its cached data is still fresh, TanStack Query can reuse that data instead of immediately fetching it again.

This means that one session does not necessarily generate three list requests. The number depends on how far the customer scrolls, whether the pages are already cached and whether a refetch is triggered.

The menu query uses a staleTime of five minutes. The menu screen and configurator share the same query, so navigating between them can reuse the same menu data.

Without a shared query key, separate components might fetch the same menu independently. With a shared query, the app can use the existing result while it remains fresh.

The five-minute freshness period reduces repeated menu requests when customers move between the menu and configurator. It does not mean that the menu can never be requested again. The query can become stale, be invalidated or refetch according to the app's query behaviour.

Configurator quotes

The configurator sends POST /v1/menu/price to obtain a quote. It debounces selection changes by 300 milliseconds before sending the request.

Suppose a customer changes an option several times in quick succession. Without debouncing, every change could generate a quote request. With debouncing, the app waits until the customer has stopped changing the selection for 300 milliseconds before sending the quote request.

This reduces unnecessary traffic while the customer is still configuring the item.

Debouncing does not guarantee one quote for an entire configurator session. If the customer makes a change, waits for the quote, and then changes another option, another request can follow.

Checkout and idempotency

Checkout sends POST /v1/orders with the cart's Idempotency-Key.

A normal checkout creates one logical order. If the request must be retried, the app keeps the same idempotency key until the order succeeds. The backend uses that key to prevent the retry from creating a second order.

This distinction matters when counting traffic. A retry can still be another HTTP request, even though it does not create another order. Idempotency protects the order creation operation from duplication. It does not make the network request disappear.

Authentication and query retries

Access tokens last 15 minutes. When requests encounter an expired access token, the API client uses silent refresh to obtain a replacement.

Concurrent 401 responses on the same device share one refresh operation. This is an example of Single-flight refresh: multiple callers wait for the same in-progress operation instead of starting independent operations.

The behaviour reduces duplicate refresh requests from one device. It does not combine refresh requests from different devices.

Your queries also retry network failures and 5xx responses at most twice. They do not retry 4xx responses. A request that fails with a retryable error can therefore generate up to three attempts: the original request and two retries.

The app also refetches queries on focus and reconnect. A customer returning to the app or restoring network connectivity can create additional traffic. These events matter when many devices experience the same interruption.

Order history

The order detail query polls every 10 seconds while the screen is focused and the order can still change.

Polling stops when the screen is covered by another screen or when the order reaches DELIVERED, CANCELLED or REJECTED.

This avoids polling for every order in a customer's history. Only focused timelines for unfinished orders contribute to the recurring polling workload.

Week 5 replaces this repeated polling with WebSockets. Until then, polling is part of the traffic generated by the mobile app.

Cache behavior and request reduction

A Cache hit rate is the fraction of data reads served from a cache without contacting the server.

For example, imagine that the app needs restaurant data 100 times. If 40 reads use cached data, the cache hit rate is 40 percent. The remaining 60 reads require network requests.

The calculation is:

cache hit rate = cached reads / total reads

network reads = total reads - cached reads

A higher cache hit rate reduces the number of read requests reaching your Go API. It does not reduce traffic from operations that must reach the server, such as checkout mutations.

TanStack Query freshness

The restaurant list uses a staleTime of 60 seconds.

typescript
useQuery({
  queryKey: ["restaurants"],
  queryFn: fetchRestaurants,
  staleTime: 60_000,
});

After fetching the result, TanStack Query considers it fresh for 60 seconds. Returning to the screen during that period can reuse the cached result.

The menu query uses five minutes:

typescript
staleTime: 5 * 60 * 1000

The longer freshness period is appropriate for menu data that does not need to be retrieved every time the customer switches between the menu and configurator.

Remember that staleTime controls freshness. It is not a guarantee that data remains cached forever, and it does not turn a query into a permanent local copy.

Several behaviours affect whether a query produces another request:

  • staleTime determines how long the result is considered fresh.
  • Query invalidation marks matching data stale so it can be refreshed.
  • Focus refetching can trigger requests when the app becomes active.
  • Reconnect refetching can trigger requests after network connectivity returns.
  • refetchInterval creates recurring requests when configured.
  • enabled determines whether a query is allowed to run.

A five-minute menu staleTime can reduce repeated requests, but it does not prevent a request after invalidation. Similarly, the restaurant list can be fetched again when its data is stale and the query is triggered.

Measuring the hit rate

You cannot calculate the actual cache hit rate from staleTime alone.

Consider two customers with the same five-minute menu freshness period. One customer visits a restaurant once. The other switches between the menu and configurator several times. Their menu query behaviour is different even though the configuration is identical.

Navigation patterns, query invalidation, reconnects, focus changes and the number of devices all affect the result.

For the worked example, you will assume a 40 percent measured cache hit rate. This is a workload assumption that makes the calculation possible. It is not a guaranteed consequence of the 60-second and five-minute freshness periods.

Response payloads

A Payload budget is the amount of data transferred for a particular screen or operation, measured in bytes.

Payload size matters because the API must send response data over the network. Larger responses consume more outbound bandwidth and can take longer to download over mobile connections.

Consider the data displayed by two screens:

  • The restaurant list needs summary fields such as restaurant identifiers, names, ratings and delivery estimates.
  • The menu screen needs menu items, descriptions, prices, sizes and option groups.

The restaurant list does not need the complete menu for every restaurant. Returning menu data with every restaurant would increase response sizes without helping the current screen.

You should return the fields the screen actually needs. This keeps the payload budget under control.

Compression

Assume the API or its reverse proxy enables gzip compression for suitable JSON responses.

An uncompressed response of 40 KB might occupy 8 KB after compression if the compressed response is 20 percent of the original size.

uncompressed response = 40 KB

compression ratio = 20%

compressed response = 40 KB x 0.20

compressed response = 8 KB

This ratio is an assumption. Actual compression depends on the response content and the compression configuration.

Compression reduces the number of bytes transferred. It does not remove the work required to construct and serialize the original response. The server also spends CPU time compressing it.

Images need separate consideration. For the worked example, assume restaurant and menu images are served from a separate static host or CDN rather than the Go API. This is an explicit assumption for the calculation, not a confirmed configuration of the course.

If images are served by the Go API, their downloads must be included in the API bandwidth estimate. An image can be considerably larger than a JSON response.

Worked traffic estimate

You will estimate the workload of a hypothetical deployment with 100,000 app installs. Each assumption is explicit so you can replace it with measured data later.

The example starts with daily activity, then estimates API requests, response bandwidth and additional traffic from order polling and token refresh.

Daily active users

Step 1: Calculate daily active users.

Assume 100,000 installs, 25 percent daily active users, two sessions per active user and 20 potential API requests per session before caching.

total installs = 100,000

daily active percentage = 25%

daily active users = 100,000 x 0.25

daily active users = 25,000

You have 25,000 daily active users.

Step 2: Calculate daily sessions.

Each active user has two sessions per day.

daily active users = 25,000

sessions per active user = 2

daily sessions = 25,000 x 2

daily sessions = 50,000

The app generates 50,000 sessions per day.

Step 3: Calculate potential requests.

Assume each session generates 20 potential API requests before caching.

daily sessions = 50,000

requests per session = 20

potential requests per day = 50,000 x 20

potential requests per day = 1,000,000

The app generates one million potential API requests per day under these assumptions.

This is the amount of activity before applying the simplified cache hit rate. It is not yet the number of requests reaching the Go API.

API requests after caching

Step 4: Apply the assumed cache hit rate.

Assume a 40 percent cache hit rate across the simplified request estimate. That means 60 percent of the potential requests reach the API.

potential requests per day = 1,000,000

cache hit rate = 40%

cache miss rate = 100% - 40%

cache miss rate = 60%

requests reaching API = 1,000,000 x 0.60

requests reaching API = 600,000 per day

The Go API receives approximately 600,000 requests per day in this model.

The cache has avoided 400,000 network requests. That is a 40 percent reduction from the original million-request estimate.

This result depends on the aggregate cache hit rate assumption. A production estimate should separate cacheable reads from quote requests, checkout operations and authentication traffic.

Average and peak RPS

Requests per second (RPS) (RPS) measures how many HTTP requests reach a service in one second.

A daily request count describes total activity. It does not tell you how much traffic arrives during a busy dinner period.

Step 5: Calculate average RPS.

There are 86,400 seconds in a day.

seconds per day = 24 x 60 x 60

seconds per day = 86,400

requests per day = 600,000

average RPS = 600,000 / 86,400

average RPS = 6.94

The average rate is approximately 6.94 RPS.

Step 6: Apply a peak factor.

A Peak factor describes how much busier the busiest period is than the average period.

Food delivery traffic is not evenly distributed throughout the day. Lunch and dinner periods can generate substantially more activity than early morning hours.

Assume a peak factor of 5.

average RPS = 6.94

peak factor = 5

peak RPS = 6.94 x 5

peak RPS = 34.7

The normal dinner peak is approximately 34.7 RPS, or about 35 RPS.

This is the baseline estimate from the simplified application activity. It does not yet include the additional cost of order polling or a token refresh storm.

Compressed response sizes

Step 7: Estimate representative response sizes.

Assume the following uncompressed response sizes:

  • Restaurant list page: 18 KB.
  • Menu response: 40 KB.
  • Gzip compression: 20 percent of the original response size.

For this calculation, assume that half of the responses are restaurant list responses and half are menu responses. Other endpoints are excluded from this simplified response mix.

Calculate the compressed response sizes first.

restaurant list size = 18 KB x 0.20

restaurant list size = 3.6 KB

menu response size = 40 KB x 0.20

menu response size = 8 KB

Now calculate the average compressed response size.

restaurant response share = 50%

menu response share = 50%

average response size = (3.6 KB + 8 KB) / 2

average response size = 5.8 KB

Under these assumptions, an API response transfers an average of 5.8 KB.

The actual average depends on the mix of restaurant, menu, order, authentication and other responses. The 50/50 mix is a modelling assumption, not a measurement of the course app.

Peak response bandwidth

Step 8: Estimate outbound bandwidth.

You have an estimated peak of 34.7 RPS and an average compressed response size of 5.8 KB.

Multiply them to estimate response bandwidth.

peak RPS = 34.7

average compressed response = 5.8 KB

bandwidth per second = 34.7 x 5.8 KB

bandwidth per second = 201.26 KB/s

Convert kilobytes per second into megabits per second. This calculation uses 1 KB = 1,000 bytes.

bandwidth = 201.26 KB/s

bytes per second = 201.26 x 1,000

bits per second = 201,260 x 8

bits per second = 1,610,080

bandwidth = approximately 1.61 Mbps

The API needs approximately 1.61 Mbps of outbound response bandwidth for this simplified peak workload.

This estimate excludes request bodies, HTTP headers, TLS overhead, retries and other endpoints. It also excludes images under the separate-host assumption.

Do not use this number as the bandwidth requirement for the combined workload later in the lesson. Order polling and refresh traffic add requests that are not represented by the restaurant and menu response-size mix.

Order polling traffic

The Week 4 order detail query uses POLL_MS = 10_000. It checks for order updates every ten seconds while the detail screen is focused and the order is unfinished.

The query stops polling when the screen is no longer focused or the order reaches a final status:

  • DELIVERED
  • CANCELLED
  • REJECTED

This focus-aware behaviour prevents an order detail screen hidden behind another screen from continuing to generate polling traffic.

The ten-second interval

A single customer viewing an unfinished order detail screen generates one request every ten seconds.

polling interval = 10 seconds

requests per second per timeline = 1 / 10

requests per second per timeline = 0.1

Now assume 1,000 customers have an unfinished order and are currently viewing its detail screen.

focused unfinished timelines = 1,000

polling interval = 10 seconds

polling RPS = 1,000 / 10

polling RPS = 100

The polling workload adds 100 RPS.

Compare it with the normal dinner peak.

normal application traffic = 34.7 RPS

orders polling traffic = 100 RPS

combined traffic = 34.7 + 100

combined traffic = 134.7 RPS

The combined workload is approximately 134.7 RPS.

Polling contributes nearly three times the normal application traffic.

polling RPS = 100

normal peak RPS = 34.7

polling to normal traffic ratio = 100 / 34.7

polling to normal traffic ratio = 2.88

A feature that looks inexpensive on one phone can become a significant source of traffic when many customers use it together.

The 1,000 customers represent focused timelines with unfinished orders. Customers viewing other screens and orders in final statuses do not add to this polling workload.

A five-second interval

Suppose you change the polling interval from ten seconds to five seconds.

focused unfinished timelines = 1,000

polling interval = 5 seconds

polling RPS = 1,000 / 5

polling RPS = 200

The combined workload becomes:

normal application traffic = 34.7 RPS

polling traffic = 200 RPS

combined traffic = 34.7 + 200

combined traffic = 234.7 RPS

A five-second interval doubles the polling traffic compared with the actual ten-second implementation. Customers may see updates sooner, but the API must process twice as many polling requests.

A thirty-second interval

Now increase the polling interval to 30 seconds.

focused unfinished timelines = 1,000

polling interval = 30 seconds

polling RPS = 1,000 / 30

polling RPS = 33.33

The combined request rate becomes:

normal application traffic = 34.7 RPS

polling traffic = 33.33 RPS

combined traffic = 34.7 + 33.33

combined traffic = 68.03 RPS

Compare the new polling rate with the original ten-second interval.

original polling RPS = 100

new polling RPS = 33.33

reduction = 100 - 33.33

reduction = 66.67 RPS

percentage reduction = (66.67 / 100) x 100

percentage reduction = 66.67%

A 30-second interval reduces polling traffic by approximately 66.67 percent. The trade-off is that a customer can wait longer to see an order status change.

The correct interval depends on how quickly the product needs to display updates. You should not reduce request volume without considering the effect on the customer experience.

WebSocket updates

Polling repeatedly asks the server for the current state, even when the order has not changed.

A WebSocket connection lets the server send an update when an order changes. The customer can receive a status event without the app making another HTTP request at every polling interval.

The traffic model changes:

  • Polling generates recurring HTTP requests.
  • WebSockets maintain persistent connections.
  • WebSocket messages are sent when relevant events occur.

WebSockets do not make traffic disappear. The backend must manage connections, send updates, handle reconnects and potentially send heartbeat messages.

When order status changes are relatively infrequent, event-driven updates can reduce unnecessary requests. Week 5 introduces this model and replaces most of the repeated order polling with live updates.

Token refresh traffic

Your API client uses silent refresh when an access token expires. Access tokens last 15 minutes, and the refresh token is stored using expo-secure-store.

The 15-minute lifetime does not mean every device sends a refresh request exactly every 15 minutes. A refresh is needed when the app makes a request that requires a valid access token and the current token has expired.

Refresh work on one device

When multiple requests receive 401 responses on the same device, they share one in-progress refresh operation.

For example, imagine that the restaurant list and order history both encounter an expired access token at nearly the same time. Instead of sending two independent refresh requests, the API client shares one refresh operation between them.

This is the purpose of single-flight. It reduces duplicated work from concurrent callers within one process.

The refresh request goes to:

POST /v1/auth/refresh

Week 3 implemented refresh token rotation. The backend checks the refresh token state in Redis and issues a replacement token pair.

The refresh path does not repeat password verification. Bcrypt is used to verify a submitted password during login, not to refresh an already issued token. Refresh still requires token validation, Redis operations, token generation and response serialization.

A reconnect event

Single-flight operates within a device. It does not combine refresh operations across all devices.

Consider an outage that causes 30,000 devices to reconnect within 60 seconds. Assume every device needs one successful refresh request during that period.

reconnecting devices = 30,000

reconnection window = 60 seconds

refresh requests = 30,000

refresh RPS = 30,000 / 60

refresh RPS = 500

The API receives an average of 500 refresh requests per second across the 60-second window.

Single-flight has reduced the work to one shared refresh operation per device. It has not reduced the number of devices that need to refresh.

If all 30,000 devices reconnect at almost the same moment, the instantaneous arrival rate can be much higher than 500 RPS. The calculated value is an average across the full minute, not a maximum arrival rate.

The refresh endpoint still consumes resources:

  1. The server parses the refresh token.
  2. It validates the token's signature and claims.
  3. It checks the token's validity and rotation state in Redis.
  4. It generates a new access token.
  5. It generates a replacement refresh token.
  6. It updates the stored token state and returns the new tokens.

These operations do not include bcrypt password verification, but they still consume CPU, Redis connections and network resources.

Combined request workload

You now have three traffic sources to consider:

  • Normal application activity: approximately 34.7 RPS.
  • Order polling: 100 RPS for 1,000 focused unfinished order timelines.
  • Refresh storm: 500 RPS averaged across 60 seconds.

Assume these workloads overlap.

normal application traffic = 34.7 RPS

order polling traffic = 100 RPS

refresh traffic = 500 RPS

combined traffic = 34.7 + 100 + 500

combined traffic = 634.7 RPS

The API receives approximately 635 RPS during this combined scenario.

This is higher than the hypothetical planning capacity of 500 RPS used later in the lesson. It is also higher than the planned sustained operating target of 350 RPS.

The combined estimate assumes one refresh request per device. Additional retry traffic during failures could increase the request volume further. The normal traffic estimate also remains based on the simplified workload assumptions.

The main point is that browsing is not the only source of load. Background polling and recovery after an outage can change the workload substantially, even when customers are not actively navigating screens.

Concurrent users and server capacity

Request rate tells you how many requests arrive each second. It does not, by itself, tell you how many requests are being processed at the same time.

For this example, assume the API runs on a modern commodity machine with four vCPUs and sufficient memory. MySQL and Redis run as separate services. The API performs relatively lightweight operations.

Assume a planning capacity of 500 lightweight API requests per second. You aim to keep normal sustained utilization below approximately 70 percent of that value.

These are hypothetical planning assumptions, not measured results for Go, MySQL or Redis.

Operating target

Calculate 70 percent of the planning capacity.

planning capacity = 500 RPS

target utilization = 70%

operating target = 500 x 0.70

operating target = 350 RPS

The initial sustained operating target is 350 RPS.

This leaves room below the assumed planning capacity. It does not guarantee that the system can sustain 350 RPS. You still need to measure how the API behaves under the actual query mix.

Concurrent customers

Assume 20 percent of the 25,000 daily active users are concurrently active during the dinner peak.

daily active users = 25,000

concurrent percentage = 20%

concurrent users = 25,000 x 0.20

concurrent users = 5,000

There are 5,000 concurrently active customers under this assumption.

Assume 20 percent of these customers have a focused order detail screen showing an unfinished order.

concurrent users = 5,000

focused unfinished timeline percentage = 20%

focused unfinished timelines = 5,000 x 0.20

focused unfinished timelines = 1,000

This matches the 1,000 timelines used in the polling calculation.

Request rate per active customer

The normal application peak is 34.7 RPS for 5,000 concurrent customers.

normal peak RPS = 34.7

concurrent users = 5,000

normal RPS per active user = 34.7 / 5,000

normal RPS per active user = 0.00694

Each concurrently active customer contributes an average of 0.00694 RPS to normal application activity under this model.

Now calculate the polling contribution. Only 20 percent of the concurrent customers have a focused unfinished order timeline. Each such timeline contributes 0.1 RPS.

focused unfinished timeline percentage = 20%

polling RPS per timeline = 0.1

polling RPS per active user = 0.20 x 0.1

polling RPS per active user = 0.02

Combine the normal and polling contributions.

normal RPS per user = 0.00694

polling RPS per user = 0.02

combined RPS per user = 0.00694 + 0.02

combined RPS per user = 0.02694

Each concurrently active customer contributes approximately 0.02694 RPS under these assumptions.

Estimated concurrent capacity

Divide the 350 RPS operating target by the estimated request rate per active customer.

operating target = 350 RPS

RPS per active user = 0.02694

estimated concurrent users = 350 / 0.02694

estimated concurrent users = approximately 12,990

The estimate is approximately 13,000 concurrently active customers.

This result assumes that normal browsing traffic and the percentage of focused unfinished order timelines scale proportionally with the number of concurrent customers. It excludes the refresh storm and additional retry traffic.

It is not a prediction of actual production capacity. The assumed 500 RPS planning capacity must be verified through load testing.

Remaining headroom at 5,000 users

At the original 5,000 concurrent users, normal activity and polling combine to produce 134.7 RPS.

normal traffic = 34.7 RPS

polling traffic = 100 RPS

total traffic = 134.7 RPS

operating target = 350 RPS

remaining headroom = 350 - 134.7

remaining headroom = 215.3 RPS

Calculate the percentage of the operating target that remains available.

remaining headroom = 215.3 RPS

operating target = 350 RPS

headroom percentage = (215.3 / 350) x 100

headroom percentage = 61.5%

Approximately 61.5 percent of the operating target remains available at 5,000 concurrent users.

A refresh storm changes the result. Adding 500 RPS of refresh traffic to the normal and polling workloads produces approximately 634.7 RPS, exceeding the assumed 500 RPS planning capacity.

This is why you need to model recovery behaviour separately from ordinary customer activity.

In-flight requests

Little's Law relates throughput, latency and the number of requests in progress.

concurrency = throughput x latency

Throughput is measured in requests per second. Latency must be measured in seconds.

Assume the combined normal and polling workload of 134.7 RPS has an average response time of 100 milliseconds.

Convert the latency into seconds:

average latency = 100 ms

average latency = 0.1 seconds

Apply Little's Law:

throughput = 134.7 RPS

average latency = 0.1 seconds

in-flight requests = 134.7 x 0.1

in-flight requests = 13.47

Approximately 13 requests are in progress at an average moment.

Now suppose the average response time increases to 300 milliseconds.

throughput = 134.7 RPS

average latency = 0.3 seconds

in-flight requests = 134.7 x 0.3

in-flight requests = 40.41

Approximately 40 requests are now in progress.

The request rate has not changed. The average latency has tripled, so the number of in-flight requests has also tripled.

More requests remain active while waiting for database queries, Redis operations or other work to finish. This can put additional pressure on goroutines, memory and connection pools.

The latency values are illustrative assumptions, not benchmark results. The calculation describes average in-flight work. It does not tell you the maximum number of concurrent connections or the exact number of database connections required.

Backend bottlenecks

A backend does not necessarily fail when CPU reaches 100 percent. Different parts of the request path can become bottlenecks independently.

The Week 4 traffic model gives you several places to investigate.

Database connections and query execution

Restaurant lists, menus and order retrieval all use backend data. Slow queries can make the database the first bottleneck even when the Go API still has spare CPU capacity.

Inspect slow queries and connection pool wait times. Use MySQL EXPLAIN to check whether frequently executed queries use the expected indexes.

The keyset pagination built in Week 2 avoids increasingly expensive large-offset pagination. It does not remove the need to inspect query plans or measure database performance.

You should also use query timeouts and avoid holding database connections while performing unrelated work.

Order polling

The actual ten-second polling interval produces 100 RPS for 1,000 focused unfinished order timelines.

That is approximately 2.9 times the normal application traffic in the worked example.

You can reduce this traffic by increasing the polling interval where freshness requirements allow it. You should also stop polling when the detail screen is not focused or the order is final.

A 30-second interval reduces the example's polling workload by 66.67 RPS. WebSockets in Week 5 replace most of the repeated polling requests with event-driven updates.

The objective is not to avoid sending status changes. It is to avoid repeatedly requesting unchanged data.

Redis and authentication

Redis handles refresh token state and other application operations.

A reconnect event involving thousands of devices can create a burst of refresh requests. Client-side single-flight reduces duplicate requests within each device, but it does not coordinate different devices.

Control retry behaviour and monitor Redis latency and connection usage. Week 3's rate limiting can also protect endpoints from uncontrolled request volume.

Go API CPU and goroutines

Go can handle concurrent requests, but each request consumes resources.

Slow database calls can leave handlers waiting while their goroutines remain active. A large number of waiting requests can increase memory use and connection pressure.

Use request-scoped timeouts and control concurrency where necessary. Do not accept unlimited work because creating goroutines is relatively inexpensive.

Response size and network bandwidth

Large JSON responses increase outbound bandwidth and serialization costs.

Return only the fields the screen needs, enable compression for suitable responses and paginate large lists. Reuse cached menu data when it is fresh. Serve images separately when that fits the deployment.

A response can waste network bandwidth even when its database query executes quickly.

Measuring the estimate

Every number in this lesson is an assumption that needs verification. The estimate gives you an initial workload for testing. It does not prove that the implementation can handle that workload.

In Week 6, you will use k6, database inspection and application metrics to replace assumptions with measurements.

Load testing with k6

Your load tests should reproduce the request patterns generated by the mobile app. Sending thousands of identical requests to one endpoint does not represent the complete customer workload.

A representative scenario should include restaurant list pages, menu retrieval, quote requests, order retrieval, order creation and authentication traffic. It should also represent different arrival rates during ordinary and peak periods.

Start with the estimated 35 RPS baseline. Increase the load gradually, then introduce the polling workload separately.

For 1,000 simulated focused unfinished order timelines, the expected polling traffic is:

simulated order timelines = 1,000

polling interval = 10 seconds

polling RPS = 1,000 / 10

polling RPS = 100

Compare the observed request rate with the estimate. Then test a 30-second interval and compare the reduction.

Measure:

  • Requests per second.
  • Response latency, including p50, p95 and p99.
  • HTTP error rates.
  • CPU and memory utilization.
  • Database connection pool waits.
  • Redis latency and connection usage.

A service that returns successful responses but takes several seconds to respond is not necessarily handling the workload well.

MySQL query inspection

Use MySQL EXPLAIN to inspect frequently executed queries.

Start with restaurant listing and order retrieval. Look for unexpected full table scans, missing indexes and expensive sorting operations.

A query that works with a small development dataset can behave differently when the tables contain hundreds of thousands of rows.

You should inspect query execution alongside connection pool waits. A query can be efficient in isolation but still contribute to connection contention when many requests execute together.

Redis measurements

Use redis-benchmark for basic Redis throughput and latency measurements.

You can also inspect application-level metrics for operations such as refresh token lookups and rotations.

A synthetic Redis benchmark does not reproduce the complete application workload. It does not account for Go handler execution, network conditions, serialization or database contention.

Measure the application path as well as the individual service.

Replacing assumptions with measurements

After running the tests, revisit the assumptions from the worked example.

Replace the assumed 40 percent cache hit rate with the measured application value. Replace the assumed 100 ms response time with observed latency. Replace the 500 RPS planning capacity with the highest sustainable rate under your chosen latency and error-rate requirements.

Measure representative response sizes and compression ratios. Replace the assumed number of focused unfinished order timelines with observed concurrent order activity.

You should also test reconnect behaviour. A system that handles ordinary dinner traffic may still struggle when thousands of devices reconnect in a short period.

Check your understanding

Question 1 of 4

A deployment has 100,000 installs, 25 percent daily active users, two sessions per active user and 20 potential API requests per session. The measured cache hit rate for this simplified workload is 40 percent. How many requests reach the API per day?

Pick an answer, then say how sure you are.

References

Everything above is explained on this page; these are where it comes from (React Native, TanStack Query, Go).

Finished Lesson 4.18?

Mobile API capacity

1 items

  • 4.18Estimating mobile API capacitynot completed

Client resilience extensions

Up next · Module 8 · 4 items · about 2 h 45 min

Start module 8