Web based API so the obvious protocol choice is https with REST as anything can integrate with this.
Serving url resolutions must be on the root path e.g. GET https://bit.ly/xyz
So the link resolution is with:
GET /
which on successful resolution returns with a redirect url containing the long url and a redirect status code.
When there is no such url then it should redirect to our systems not found page.
The link creation is at:
POST /api/v1/urls
That accepts in the body: url, optional expiration time and headers like the anonymus users IP.
On success the response contains the original url and short url.
The service live in USA, Europe and Asia regions.
The client's traffic will connect to an API Gateway that serves many purposes:
The API GW connects to url resolution service:
The URL management service is responsible for
URL generation:
ID Generation DB:
URL Resolver Database:
URL Resolution service is stateless, it can scale horizontally well, without problems. It is behind a load balancer.
Url Resolver Datatabase is a global dynamodb being in multiple regions. Which means that it is eventual consistent globally, but scales out well, even automatically, Highly Available, has failover to other availability zones or region and provides low latency. Eventual consistency is the tradeoff for the sake of low latency and high availability.
The load on URL Management service is low, just a couple of instances (3) behind a load balancer / region. All instances connect to the ID Generation database in the EU region to generate the next id they can assign to a long url. Once it has an id it saves the url with that in the URL resolver database. There is an issue here with a committed id in the id generation database when saving the url in the resolver database fails.
The ID Generation database is a single master postgres with a hot failover replica in EU.
This will result in high latency for non EU accesses but guarantees the sequential id issuing.
API GW caching:
API GW: