Design a Tagging Service
Understanding the Problem
🏷️ What is a tagging service? A tagging service lets users attach short labels ("payments", "q3-launch", "bug") to things in several products, and then use those labels to find related work. A company with an issue tracker, a wiki and a code host (Jira, Confluence and GitLab are the usual example) wants one shared tag vocabulary, so that clicking "payments" on a ticket shows the matching wiki pages and merge requests too. The tagging service owns the tags and the links between tags and items; each product still owns its own items.
The interesting part of this question is that it's not one product's feature. The service sits beside several products, it doesn't own the items it labels, and it has to answer questions across all of them. Most of the design follows from that.
Functional Requirements
We'll start by agreeing with our interviewer on what users can do. Tag management can grow into a big admin product (renames, merges, synonyms, colors), so it's worth drawing a line early.
Core Requirements
- Users should be able to add and remove tags on an item in any of the integrated products, and see an item's tags when they view it.
- Users should be able to click a tag and see all items with that tag, across products, newest first.
- Users should be able to see popular tags, overall and per product, for a recent time window (for example, the last 7 days).
Below the line (out of scope)
- Tag autocomplete while typing. It's a typeahead problem on a small vocabulary; we'll mention it at the end.
- Tag renames, merges and synonyms beyond a brief note.
- Full-text search over item content. Products own their own search.
Non-Functional Requirements
Ask your interviewer how big this is. Let's say the tag service is shared by about 50,000 customer organizations (tenants), with 2 billion taggable items across all products, and an average of 3 tags per item, so about 6 billion tag assignments.
Core Requirements
- The system should return an item's tags in under 20 ms at p99, because those tags are rendered on every item page in every product.
- The system should return the first page of a tag's items in under 200 ms, even for a tag with millions of items.
- The system must never show a user an item they aren't allowed to see. A tag listing that leaks the title of a private page is a security bug.
- The system should show a user their own tag change immediately (read-your-writes). Popular tag counts can be minutes stale.
- The system should keep tenants fully isolated: one tenant's tags and counts are never visible to another.
Below the line (out of scope)
- Multi-region active-active writes. We'll assume each tenant lives in one home region.
- Analytics on tag usage beyond the popular list.
Now the back-of-the-envelope. Tagging is rare: people add a tag a few times a day, maybe 20 million tag changes a day across all tenants, which averages about 230 writes per second and peaks at a couple of thousand. Reading tags is constant: if items are viewed 1 billion times a day, that's about 12,000 item-tag lookups per second on average and perhaps 50,000 at peak. Tag pages are clicked far less, perhaps 1,000 per second. Storage: 6 billion assignments at roughly 100 bytes each is about 600 GB for one direction. We'll want two directions (item to tags, tag to items), so call it 1.2 TB plus indexes.
The arithmetic says writes are tiny and storage is modest. The hard parts are elsewhere: one tag can have millions of items (one huge partition), every listing must be filtered by permissions we don't own, and "popular" is a counting problem. Say this early so your interviewer knows where you want to spend time.