Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
State:
> Mapping
>> CREATE /mapping/create
JSON body
>> UPDATE /mapping/edit/
JSON body
>> DELETE /mapping/delete/
No body
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
State = mapping
Storage:
Services:
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
Account Table:
accountId (PK) | Name | Address | Status (active)
Slug Table
slug (PK) | accountId
KV Store
slug | url
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
Let's talk about slug generation and how to make it scale. Here's the plan.
We shard SQL DBs on slug. eg.
The first three letters have 62 * 62 possibilities = 3, 844, Let's divide this into 100 shards
Now we have multiple slug jobs, where each job also divides its work be randomly choosing the first two letters within a give shard range, (i.e. 100 different ranges), and then the last 5 letters are completely random using entropy.
Each customer account, on creation is assigned to one of these 100 shards.
Therefore that customer will ALWAYS use slugs that starts with letters that are part of their shard.
e.g. assume the first shard is aa - cc then, all slugs first this customer start with that range:
aaGGTT5, bcYY779
Consider:
> slugs are sharded into 100 groups. Therefore at 1000 RPS, only 10 writes are attempted per shard
> Also consider that the slugs are NOT derived on demand, but in advance, so the expensive computation is offloaded
in asynchronous jobs
> The ONLY real bottleneck is the Write contention on slug creation, and assignment of slug to account. But at 10RPS per shard, we should be able to handle this.