. a post request containing the long url , user id and expiration time and return short url
flowchart TD A[Client] -->|1) Send Long URL| B[API Gateway] B -->|Route Request| C[Shortening Service] C -->|Check Short URL| D[Database] D -->|Exists?| D -->>|Yes| C -->|Return Error| B D -->>|No| C --> |Create Mapping| D C -->|Store Mapping (short_url, long_url, TTL)| D C -->|Update Cache| E[Cache] E -->|Store (short_url, long_url, TTL)| C C -->>|Return short URL| B B -->>|Response (short URL)| A A -->|2) Send Short URL| B B -->|Route to Redirect| F[Redirecting Service] F -->|Check Cache| E E -->|Found?| E -->>|Yes| F -->|Return long_url| B E -->>|No| F -->|Check Database| D D -->>|Found?| D -->>|Yes| F -->>|Return long_url| B D -->>|No| F -->>|Return Error| B B -->>|Final Response| A
for database, it can scale by have read replication for reading data and write database for writeing data
for memory database it can scale by sharding
url_mappings { string short_url "Primary Key" string long_url "URL being shortened" string user_id "Foreign Key referencing users (optional)" date created_time "Timestamp of creation" date expiration_time "Timestamp when the URL expires (optional)" int click_count "Count of redirections (optional)" }
index the short url