AlgoViz

Throughput

easy 30 min

Throughput is how much work a system finishes per second.

See it run

How much work gets finished per second, which stage limits it, and what really raises it.

Operations

One server to eight

400 requests arrive every second. One server finishes 100.

Step 1 of 5

One server

Load balancerServer 1100/s
Busy
100%

arrive

400/s

finish

100/s

queue grows

300/s

It finishes 100. The queue grows by 300 every second.

Step 1: One server

def finished(arriving, servers, each=100):    return min(arriving, servers * each)def queue_growth(arriving, servers, each=100):    return max(0, arriving - servers * each)
Answers
How many servers?
You leave with
Capacity, with room

Four are enough on paper and completely busy. Six leave each at 67%.

In the real world

The same throughput doing real jobs. Pick one and step through it.

One small system, improved step by step. Each number can be worked out.

Step 1 of 5

Start

StepReasonThroughput
Nothing2 connections, 20 ms100/s
+ Pool
+ Cache, 80%
+ Batch of two
+ 4 machines

Two connections. Each request needs 10 ms to connect and 10 ms to query: 2 / 0.02 = 100 a second.

Step 1: Start

Common mistakes

The bugs interviewers watch for, with the fix beside each.

  • Widening the wrong stage

    critical

    Capacity of a chain is its minimum. Anything else changes nothing.

    Wrong
    scale(api, 4)        # api is 30% busy
    Right
    stage = min(capacity, key=capacity.get)scale(stage, 2)
  • One call per row

    major

    A round trip and a commit for every row.

    Wrong
    for r in rows:    db.insert(r)          # 1,000 x 5 ms
    Right
    db.insert_many(rows)      # 50 ms
  • A queue without a limit

    critical

    It grows until memory ends, and old work is useless by the time it runs.

    Wrong
    queue = []            # forever
    Right
    queue = Queue(maxsize=1000)# full: answer 429 at once
  • Counting attempts

    minor

    Errors are quick, so a failing system looks busy and healthy.

    Wrong
    meter.record(); handle(req)
    Right
    handle(req)meter.record()        # only after success

Interview tips

  • How to explain it

    • Finished work per second.
    • The narrowest stage decides.
    • Higher is better, for capacity.
  • Three formulas

    • In progress = rate × time.
    • Stage = workers / time.
    • Cache: 1 / (1 - hits).
  • Raise it by

    • Parallel workers, batches.
    • Caches, pools.
    • Balancing, queues and workers.
  • Watch out

    • Bandwidth is a limit, not a result.
    • Retries past saturation.
    • A weak test client.