CSE Roadmap

Common tier · about 4 hours · 8 parts

Part 8 of 8 · 2 min read

Exercises

Easy

Easy 1: Rates (20 minutes)

2 million daily players, 8 wins each. Give the average updates per second and the peak at 5 times.

Done when: you write about 185 and about 926 per second.

Hint

2,000,000 × 8 / 86,400.

Easy 2: Memory (20 minutes)

10 million players at 26 bytes each. Give the size, and the size when doubled.

Done when: you write 260 MB and 520 MB.

Hint

10,000,000 × 26 bytes.

Easy 3: Commands (20 minutes)

Write the command that adds a point to player "ana", the one that lists the top 10, and the one that gives her rank.

Done when: you write ZINCRBY, ZREVRANGE with 0 and 9 plus WITHSCORES, and ZREVRANK.

Hint

Use the REV versions, so the highest score comes first.

Medium

Medium 1: Overall rank (30 minutes)

Three score shards hold 40 players (high), 60 (middle) and 100 (low). A player is rank 15 inside the middle shard. Give the overall rank.

Done when: you write 40 + 15 = 55.

Hint

Add the sizes of all higher shards.

Medium 2: Neighbours (30 minutes)

A player's rank is 361, counting from 0. Write the range for four players above and four below.

Done when: you write ranks 357 to 365.

Hint

Subtract and add 4 to the rank.

Medium 3: Write shards (30 minutes)

A month has 1,200 writes per second and one partition handles 300. How many partitions are needed, and how many queries does a month read need?

Done when: you write at least 4 partitions and 4 queries, merged.

Hint

1,200 / 300.

Hard

Hard 1: Draw the design (60 minutes)

Draw the game service, leaderboard service, Redis primary and replica, MySQL tables and the user cache. Mark the update and read paths.

Done when: a diagram with two numbered paths and the rebuild job.

Hint

The point table feeds the rebuild job.

Hard 2: Recovery plan (60 minutes)

Redis and its replica both fail at 3 pm. Write the steps, and estimate the rebuild time for 25 million players at 100,000 users per second.

Done when: a plan with steps and a rebuild time of about 250 seconds.

Hint

25,000,000 / 100,000.

Hard 3: Mock interview (60 minutes)

Answer "design a leaderboard" aloud in 35 minutes and mark yourself on the four steps. List two missed topics.

Done when: a recording, a score on each step, and two named gaps.

Hint

Use the four-step framework as a checklist.