Detailed component design
- code-generator-service: used in the create url flow. Generates a unique code, save on redis and return 202 status code with short url.
- url-writer-service: listen pubsub topic, pull messages in batch and write on postgres in batches
- url-query-service: read from redis based on code, if cache miss, fetch data from replica postgres database written by url-writer-service
Database design
Postgres database to provide long-term history of short-url:
- Table short_urls
- id int sequential (PK)
- full_url text not null
- code varchar (20) not null -> index btree
- reference_id varchar (50) -> unique idempotency key
- expires_at datetime nullable -> used to ignore on expired read
- created_at
Postgres database to provide complete report history:
- Table urls
- id int sequential (PK)
- code varchar (20) not null -> index btree
- read_count bigint default 0
- created_at