AlgoViz

Queries per second

easy 30 min

QPS is how many queries arrive, or can be answered, each second.

Video lesson · Chapter 1 of 6

From users to a rate

0:00 / 5:07

From a day to a second

1:10Reel coming soon

Theory

Read or listen first. About 1 min.

What it is

QPS, queries per second, is a rate: the number of queries divided by the seconds in which they came. 600 questions in one minute are 10 QPS.

The word has two uses. Load is the QPS that arrives. Capacity is the QPS a system can answer while still meeting its latency target. A design is fine as long as load stays well below capacity, also in the busiest minute.

Why it exists

Products are described in people and days: a million users, twenty views each. Machines are described in seconds. QPS is the bridge between the two.

It is the first number in most design interviews, because it decides early whether one database is enough, whether reads need a cache and whether writes must be split.

A short history

  1. 1909

    A. K. Erlang publishes a first work on telephone calls as random arrivals. Telephone engineers plan for the busiest hour, not for the average.

  2. 1985

    A paper in Datamation, prepared by Jim Gray and colleagues, proposes a common way to measure transactions per second.

  3. 1988

    The Transaction Processing Performance Council is founded and turns that idea into audited benchmarks.

  4. 2012

    Prometheus is started at SoundCloud. Its counters and rate() function later become a usual way to graph requests per second.

  5. 2024

    Amazon reports that DynamoDB peaked at 146 million requests per second during Prime Day.

Words to know

Average QPS
Queries in a day divided by 86,400.
Peak QPS
The rate in the busiest time. We plan with three times the average.
Spike
A short jump far above the usual peak.
RPS
Requests per second, usually HTTP requests.
TPS
Transactions per second.
Read to write ratio
How many reads come with each write, such as 100:1.
Headroom
Capacity kept free for bumps and failures.

How it works

Step through the idea, or press Play.

Step 1 of 3

Average. Daily total / 100,000

Understand it

Start here

The zoo information desk

Imagine the information desk at a zoo. Visitors ask, "Where are the penguins?" The clerk answers. The number of questions answered in each minute is the desk's rate. Computers are quicker, so for them we count each second.

One desk, quiet days and a school trip
INFORMATIONWhere are the penguins?6 answers a minute

8 / (6 × 0.7) = 1.9, so 2 clerks, and 1 spare makes 3.

Words

QPS, RPS and TPS

CountsCommon for
QPS, queriesOne question to a system: a search, a SQL statement, a cache lookupSearch engines, databases, caches
RPS, requestsAll HTTP requests, reading and writingWeb servers, APIs, load balancers
TPS, transactionsAll-or-nothing units, each perhaps several queriesPayments, banking, order systems
People mix the words. What matters is which work is counted, and where.

The rate changes on the way

Users send 100 requests a second to one server that can do 200. For each request the server makes three queries to the database: 300 queries a second, against a planning line of 10,000.
100 requests a second become 300 database queries. The server is 50% busy, the database 3%.

One request, several queries

DB QPS=RPS×queries per request×(1−hit rate)100×3=300\text{DB QPS} = \text{RPS} \times \text{queries per request} \times (1 - \text{hit rate}) \qquad 100 \times 3 = 300
With an 80% cache hit rate only 60 would reach the database.

Why

Why it matters

Load below capacity

  • Answers stay fast
  • Users see results at once
  • Bumps are absorbed
  • No queues, no timeouts

Load above capacity

  • Requests pile up in queues
  • Latency climbs steeply
  • Timeouts and errors, then retries
  • The system may stop answering

Calculate

Three formulas

Basic, and from daily users

QPS=queriesseconds,average=daily users×queries each86,400\text{QPS} = \frac{\text{queries}}{\text{seconds}}, \qquad \text{average} = \frac{\text{daily users} \times \text{queries each}}{86{,}400}
1,000,000 queries in 1,000 s are 1,000 QPS. 600 in a minute are 10 QPS. A day is 24 × 60 × 60 = 86,400 s.

Peak

peak≈3×average\text{peak} \approx 3 \times \text{average}
Two to three times is usual for a day with a busy evening. We plan with three. If you have traffic data, use it.

Quick reference

Per dayAverage, exactIn your head (/ 100,000)Peak, × 3
1 million11.6/s10/s30/s
100 million1,157/s1,000/s3,000/s
1 billion11,574/s10,000/s30,000/s
10 billion115,741/s100,000/s300,000/s
The shortcut is 14% low. That never changes a decision made in factors of ten. See Numbers that decide.

Worked examples

Two sums from start to decision

A short-message service

StepSumResult
Daily usersassumed100 million
Queries eachassumed50
Per day100M × 505 billion
Average5 billion / 86,40057,870/s (50,000 in your head)
Peak× 3about 174,000/s (150,000)
So17 times one database's planning linereads from cache, data split

A URL shortener

StepSumResult
New links10 million a day / 86,400116 writes/s
Reads100 for each write11,574/s
Together116 + 11,57411,690/s average
Peak× 3about 350 writes/s and 35,000 reads/s
Sowrites are easy, reads are notone database for writes, a cache for reads
Never add reads and writes and stop there: they need different answers. The whole design is in URL shortener.

From users to a decision

Distribution

Traffic is not flat

A school cafeteria sees 5 children at 9 and 500 at noon. The average is 50 an hour, and nobody is helped by that number at noon.

Python
load = {0: 20, 2: 10, 4: 8, 6: 15, 8: 45, 10: 70, 12: 85, 14: 75, 16: 65, 18: 80, 20: 100, 22: 55}for hour, v in load.items():    mark = "peak" if v > 80 else "moderate" if v > 50 else "low"    print(f"{hour:02d}:00 {'#' * (v // 4):25s} {v:3d} {mark}")avg = sum(load.values()) / len(load)print(f"average {avg:.0f}, peak / average {max(load.values()) / avg:.1f}")# three regions, eight hours apart: the sum is much flatterv = list(load.values())world = [v[i] + v[(i + 4) % 12] + v[(i + 8) % 12] for i in range(12)]print(f"world: peak / average {max(world) / (sum(world) / 12):.2f}")
A typical daily shape, every two hours, 100 = the busiest. The peak here is 1.9 times the average: three is a careful choice.
Edit and run it in your browser

Average, peak, spike

ExampleWhat to do with it
Average1,000/sCost and storage
Peak, 2 to 3 times3,000/sNormal capacity
Spike, 10 times or more10,000/s and upProtect: cache, queue, waiting room, limits

Four traffic patterns (the ratios are rules of thumb)

  • Day and night

    Peak in office hours. Business tools. 2 to 3 times.

  • Evening

    Peak after work. Streaming, games, social. 3 to 5 times.

  • Weekly

    Weekend differs from weekday. Shops, travel. 2 to 4 times.

  • Events

    News, live sport, flash sales. 10 to 100 times, at once.

Which peak do I use?

Geography

Follow the sun

Three regions, three evenings

Users in Asia Pacific, Europe and the Americas each reach their own region: a load balancer with servers. Each region carries its own evening peak; data is copied between the regions asynchronously.
Busy hours are roughly 8 or 9 in the morning to 10 or 11 at night, local time. Dashed is asynchronous copying.

When each region has the daily curve above, eight hours apart, the world peaks at only 1.2 times its average. But users go to the region near them, so each region still needs its own peak: 1.9 times. Size regions, not the world.

Capacity

How many servers?

For a birthday party with 20 invited children you prepare 30 bags, because some bring a brother, and you keep a room free in case it rains. That is headroom.

Machines

n=⌈peakcapacity of one×0.7⌉+1n = \left\lceil \frac{\text{peak}}{\text{capacity of one} \times 0.7} \right\rceil + 1
70% leaves room for bumps and keeps queues short. The spare covers one failure. The capacity of one must come from a test.

An online shop

StepSumResult
Per day10M users × 20 pages × 5 calls1 billion
Average1 billion / 86,40011,574/s
Peak× 334,722/s
Needed at 70%34,722 / 0.749,603/s of capacity
Servers at 1,000/s each⌈49.6⌉ + 151
With a 2x buffer instead34,722 × 2 / 1,000about 70
Both rules are in use. 70% is a buffer of 1.43. A buffer of 1.5 to 2 costs more and survives more. Say which you use and why.

Scale

Raising QPS

Out: more servers

  • Close to linear for stateless servers
  • Good for APIs
  • Needs load balancing
  • Survives losing one

Up: a bigger server

  • Faster CPU, more RAM, SSD
  • Limited by the largest machine
  • Good for databases
  • Still one thing that can fail: see vertical scaling

Quick wins, and how to work out the gain

MoveGainWhy
Caching1 / (1 - hit rate): 10x at 90%, 100x at 99%Only misses reach the store
Connection pool(open + query) / queryLarge if opening is slow
Query optimisationTime before / time afterAn index can turn seconds into milliseconds
Read replicasUp to the number of copies, for reads onlyEvery write still goes to every copy
These replace fixed promises such as "2 to 5 times", which depend on your system.

Peak is above one machine. What now?

Real sizes

What is large?

Published by the owners

SystemPublishedPer second
Google Search (2025)More than 5 trillion searches a yearabout 158,000 average
Amazon DynamoDB, Prime Day 2024146 million requests a secondpeak
Amazon ElastiCache, Prime Day 2024Over 1 trillion requests a minuteabout 17 billion at peak
5 × 10¹² / 31,536,000 s = 158,549. Many other company figures online have no primary source.

One node, to plan with

SystemSimple operationsRemember
MySQL or PostgreSQL10,000/s as a planning lineA heavy query can use a whole core; a tuned machine goes further
Redis100,000/sThe docs show a benchmark near 180,000
MongoDB, CassandraNo single numberDocuments, nodes, replicas and consistency change it
ElasticsearchFar fewer: each search does more workDepends on index size and the query
Rules of thumb. Actual QPS depends on queries, data, hardware and settings: test your own work.

Interview

Do and avoid

Do

  • Work QPS out from the requirements
  • Split reads and writes
  • Use a peak of 3 times
  • Add headroom: 70% and a spare
  • Mention a cache when reads repeat and the number asks for it

Avoid

  • Skipping the sum when a decision waits for it
  • Planning for the average
  • Forgetting the read to write ratio
  • Forgetting that the database is often the limit

Watch it live

Below half of capacity is calm, above 70% plan to add, above 100% requests queue.

Summary

The whole topic in one minute.

Average QPS is the daily total divided by 86,400, or 100,000 in your head. Multiply by three for an ordinary peak, and count people instead when a clock brings them together.

Split reads and writes, multiply by the queries each request makes, then divide the peak by 70% of what one tested machine can do, and add one spare.

  • QPS = queries / seconds. A day is 86,400 s.
  • Average × 3 is the peak; a clock-driven rush counts people.
  • Reads and writes apart, and one request may be many queries.
  • Machines: peak / (capacity × 0.7), rounded up, plus one.
  • End with a decision.

Sources