retrystorm · Learn · Interview practice · Glossary · Components

Home › Interview practice › Mint the Codes

Mint the Codes

Hand out short, unique codes from many app servers at once, fast enough for a bulk import.

ink.ly, Inkwell's link shortener, launches next week. A partner wants to import its links on day one: thousands of new short codes a second, minted by every app server at once. No two links may ever share a code, and codes have to stay short: 7 characters, so UUIDs (36) and Snowflake IDs (about 11) are out.

What it does

  • Write: create a short link. The app server asks the ID generator for a code, then stores the link.
  • Read: open a short link.

Workload

A steady 6 000 rps, 90% writes / 10% reads, for 10 seconds. Every write creates a new link.

How to build it

The app tier and the database are fixed and big enough. You choose how codes are minted.

  1. Build client, load balancer, app server and database. Add an ID generator and connect the app server to it, carrying writes (W) only.
  2. Start with a central counter (it hands out up to 5 000 codes a second) and run it. Look at the p99.
  3. Keep creating a link fast. The counter can hand each app server a block of codes per call (codes per call), or the servers can hash each link into a short code and try again on a clash.

Part of Chapter 26: Unique IDs.

About · Contact · Privacy · Terms of use