Middle — Senior
Data distribution in the database through sharding
livecode
Task condition
Service architecture:
- Clients send POST requests to create shortened URLs and GET requests to retrieve the original address.
- All requests pass through an API Gateway, which provides load balancing and access control.
- Requests are routed to separate microservices TinyUrlPOST and TinyUrlGET.
- The main storage is a MySQL database serving both types of requests.
Based on the described scheme, formulate a database sharding plan:
- What criterion (e.g., by short_link field or by user_id) should be used to divide data;
- What strategies (range-based, hash-based, list-based, etc.) can be applied;
- How to ensure scalability and even load distribution among shard nodes;
- How to implement a request routing mechanism to the appropriate shard.