DynamoDB is a fully managed, serverless, key-value, NoSQL database designed to run high-performance applications at any scale. DynamoDB offers built-in security, continuous backups, automated multi-Region replication, in-memory caching, and data export tools.
For scaling lets use NoSQL
for high volume
we cannot store user id
create a third table to store user id
Encoding
with 8 letter encoding 64
64^8 = 281 trillion string
with MD5 it will generate 128bit
64.8 billion will suffice
Data partition & replication
Range based partitioning
inconsistently distributed across servers
Hash based partitioning
easy to read
faster
consistent hashing to distribute across servers
Linked hash map
store URL's with hash for easy retrieval
High-level design
client
loadbalancer
API gateway
DB
Cache
LFU
Expired ones
KGS
encoding
Request flows
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
Detailed component design
Key Generation Service
base 64 algorithm
64 billion unique ones
Generate keys offline
By generating offline we will miss sequence
we might waste some of them if the server dies down
concurrency issue might be a concern
Single point of failure
key look up - 302 redirect and 404 not found
maximum of 16 characters long key
Caching
Redis
No longer need to perform management tasks such as hardware provisioning, software patching, setup, configuration, and failure recovery
Have access to monitoring metrics so you can diagnose and react to issues quickly
Can take advantage of cost-efficient and resizable hardware capacity
store full url's with hash
we will store 20% of the cache which will fit into one server
hotspots
LFU
Purging/clean up
expired one's can be removed and new ones inserted
Load balancers
round robin method
what comes in will go out and sequentially processed one at a time
Trade offs/Tech choices
MD5 algorithm
128bit will make 16 characters which will generate trillions of strings
since billions are good enough at this point lets use the basic 64 bit algorithm
load balancer
we can use more intelligent lb to handle the traffic and route it appropriately based on the load