# TikTok For You feed system design, running live

Source: https://systemdesignsim.com/blueprints/tiktok

Social and feeds · Foundations · Cached feed pages behind a load balancer

The feed is a read: the app asks for the next batch of videos as you scroll. Six web servers behind a load balancer answer most of those requests from the cache, and Postgres keeps likes, follows and video records. Ranking and video delivery are left out so the request path stays easy to see.

A teaching design of a system like TikTok, not TikTok's real architecture. Traffic, capacity and cost are simulator estimates. [Model and assumptions](https://systemdesignsim.com/methodology).

* Traffic

  3,000 req/sMedium scale

* AWS bill

  $1,000/mo

* p99

  66 ms

* Components

  4

3,000 requests a second, 5% of them writes. That's a busy SaaS product or a mid-sized shop at its daily peak.

[Open it running](https://systemdesignsim.com/playground?blueprint=tiktok)

![TikTok For You feed architecture on AWS at 3,000 requests a second](https://systemdesignsim.com/blueprints/tiktok.svg)

TikTok For You feed architecture on AWS at 3,000 requests a second. Scroll the diagram to see every component. The small text under a box is its traffic, instance count or shard count.

## How it works

1. A request reaches the load balancer, which picks a healthy web server. A server that fails its health check stops getting traffic.
2. The web server asks the cache first. Nine reads in ten are answered there in a couple of milliseconds.
3. Cache misses and every write go to Postgres. Writes land on the primary; the replica serves reads and is ready for a failover.
4. At 3,000 requests a second the six servers run at about half their capacity. That spare half is what absorbs a launch or a bad deploy.

## What each part does

* Visitors

  3,000 requests a second, 95% reads. Change it and watch the rest of the design react.

* Web servers

  Six m7g.large servers. The simulator gives each about 1,000 requests a second, so they sit near 50% busy.

* Cache

  One cache.r7g.large node. At a 90% hit ratio it turns 2,850 reads a second into about 285 database reads.

* Database

  Postgres on db.r7g.large: a primary for writes and one read replica.

## What breaks first

The web servers. They hit their limit at about 1.9x the preset (5,700 req/s), while the database is still only half busy.

Past that point requests queue inside each server until it runs out of room, crashes and restarts, and the restarts push more load onto the survivors. At 4x almost every request fails. The fix is more servers, or autoscaling that adds them before the queue builds rather than after.

The simulator checks this every build: it runs the design at 3,000 req/s, then ramps traffic to 4x (12,000 req/s) and records which part fails first. In the playground, press Break it to watch the same thing happen.

## Trade-offs

### What it gets right

* Easy to run, debug and hire for. Every framework tutorial ends up here.
* One cache node removes most of the database load for about the price of one web server.

### What it costs you

* The web fleet is fixed. Traffic that doubles in a few minutes outruns it before anyone adds servers.
* One primary takes every write, so a write-heavy product eventually needs sharding or a different store.
* Drop the hit ratio to 50% and the database sees five times the reads. The cache is quietly holding the design up.

## In the real world

* Most Rails, Django and Laravel apps run like this for years: a load balancer, a few app servers, Redis or Memcached, and Postgres or MySQL.
* Stack Overflow is the well-known example of serving a huge site from a small, carefully tuned set of web servers, SQL Server and Redis.

## In the interview

* Start here even for a big 'design X' question, then say which number forces each change.
* Do the cache arithmetic out loud: at a 90% hit ratio one read in ten reaches the database. Say what that comes to for the traffic you were given.
* When failure comes up, mention health checks and keeping one spare server so losing one doesn't overload the rest.

## Run it yourself

The playground opens this design with 3,000 requests a second already flowing. Press Break it, or change one part yourself, and watch which number goes first.

[Open it running](https://systemdesignsim.com/playground?blueprint=tiktok)

Read the walkthrough: [Design a Short Video App like TikTok](https://systemdesignsim.com/system-design/tiktok)

## Questions people ask

### How does TikTok For You feed work at the system design level?

A request reaches the load balancer, which picks a healthy web server. A server that fails its health check stops getting traffic. The web server asks the cache first. Nine reads in ten are answered there in a couple of milliseconds. Cache misses and every write go to Postgres. Writes land on the primary; the replica serves reads and is ready for a failover. At 3,000 requests a second the six servers run at about half their capacity. That spare half is what absorbs a launch or a bad deploy.

### What breaks first in a TikTok For You feed design?

The web servers. They hit their limit at about 1.9x the preset (5,700 req/s), while the database is still only half busy. Past that point requests queue inside each server until it runs out of room, crashes and restarts, and the restarts push more load onto the survivors. At 4x almost every request fails. The fix is more servers, or autoscaling that adds them before the queue builds rather than after.

### What are the trade-offs of this TikTok For You feed architecture?

Easy to run, debug and hire for. Every framework tutorial ends up here. One cache node removes most of the database load for about the price of one web server. The web fleet is fixed. Traffic that doubles in a few minutes outruns it before anyone adds servers. One primary takes every write, so a write-heavy product eventually needs sharding or a different store. Drop the hit ratio to 50% and the database sees five times the reads. The cache is quietly holding the design up.

### What do interviewers look for in a TikTok For You feed system design answer?

Start here even for a big 'design X' question, then say which number forces each change. Do the cache arithmetic out loud: at a 90% hit ratio one read in ten reaches the database. Say what that comes to for the traffic you were given. When failure comes up, mention health checks and keeping one spare server so losing one doesn't overload the rest.

## More in social and feeds

* [Instagram feed](https://systemdesignsim.com/blueprints/instagram-feed)
* [LinkedIn feed](https://systemdesignsim.com/blueprints/linkedin)
* [Live comments](https://systemdesignsim.com/blueprints/live-comments)
* [Reddit](https://systemdesignsim.com/blueprints/reddit)
* [Twitter timeline](https://systemdesignsim.com/blueprints/twitter-timeline)
* [All blueprints](https://systemdesignsim.com/blueprints)

## One system design problem a week

A real scenario, its constraints, and where the obvious design breaks.

## Now break one yourself.

The first challenge takes about two minutes. No signup.

[Design your first system](https://systemdesignsim.com/challenges/hello-load-balancer)
