CSE Roadmap

Core tier · about 4 hours · 8 parts

Part 8 of 8 · 3 min read

Exercises

Easy

Easy 1: Test the key (20 minutes)

Test these keys against the four tests: country for users, user_id hashed for users, sequential order id with range partitioning, device id hashed for readings.

Done when: a table of four keys against four tests.

Hint

High cardinality, even use, local queries, never changes.

Easy 2: Partition key and sort key (20 minutes)

Give a partition key and a sort key for: messages in a channel, readings of a sensor, orders of a user, comments under a post.

Done when: four pairs with a reason.

Hint

The partition key is what every query names.

Easy 3: Queries and shards (20 minutes)

A table of orders is sharded by user_id across 32 shards. Give the number of shards touched by: one user's orders, one order by id with no user in the id, all orders yesterday.

Done when: three counts.

Hint

A query that names the key touches 1 shard. Otherwise all 32.

Medium

Medium 1: Size a chat store (30 minutes)

8 million channels, 25 messages per channel per day, 250 bytes each. Compute the daily and yearly data and the shards needed at 3 TB each. Add 30 percent growth.

Done when: daily size, yearly size and a shard count.

Hint

Daily bytes = channels × messages × size.

Medium 2: Hot channel (30 minutes)

A channel gets 800 messages a second. A shard takes 5,000 writes a second and 3 TB. Compute the share of one shard's write capacity this channel uses, its yearly data and the bucket size (hours) that keeps each bucket under 100 GB.

Done when: a share, a yearly size and a bucket size.

Hint

Write share = 800 ÷ 5,000. Bucket size = 100 GB ÷ bytes per hour.

Medium 3: Time series layout (30 minutes)

20,000 sensors send 1 reading a second of 40 bytes. Compute writes per second, bytes per day, and the size of one sensor-day partition. Propose a retention plan with roll-ups.

Done when: three figures and a retention plan.

Hint

One sensor-day = 86,400 × 40 bytes.

Hard

Hard 1: Shard an online marketplace (45 minutes)

Design keys for users, listings, orders and messages in a marketplace. For each give the key, the five queries and shards touched, one hot-key risk and one remedy.

Done when: a table for four entities with queries and remedies.

Hint

A messages table needs the channel or conversation as the partition key.

Hard 2: Resharding plan (45 minutes)

A user table is sharded by country and one country holds 70 percent of the data. Plan the move to a hash of user_id with no downtime: steps, the log used to keep copies in step, the cut-over for reads and writes, the checks and the rollback. Estimate the time for 4 TB at 200 MB/s.

Done when: a numbered plan, checks, rollback and a time estimate.

Hint

Dual-write or log shipping keeps the new layout in step. 4 TB ÷ 200 MB/s.

Hard 3: Review a design (50 minutes)

Take any case study you know (a URL shortener, a news feed or a ride-sharing app). Apply the checklist to its shard key choices. Write the verdict for each of the eight items and the one change you would make.

Done when: an eight-line review and one named change.

Hint

Use real numbers from the case study.