Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
1) Endpoints
2) HTTP methods
3) Request and Response Formats
4) Error Handling
5) Authentication and Security
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
We need microservices where each service (Like URL creation and redirection) operates independent. To ensure unique identifiers to avoid collisions the service can create a hash. We need an API gateway to manage requests. To improve performance and reduce latency we can have a dedicated service for URL shortening that interacts with a caching layer. If a user requests that same URL we can respond back with the cache and have a TTL of 24 hours so that it doesn't become stale. In order to handle data storage, we can use a NoSQL database since we don't need a relational database and we can scale horizontal if needed.
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
To enhance your design regarding cache management, consider specifying an eviction policy that balances memory usage and data freshness effectively. One common approach is to implement a Least Recently Used (LRU) eviction policy. This policy removes the least recently accessed entries from the cache when it reaches its memory limit, ensuring that frequently accessed data remains available while older, less relevant data is purged.
You can also define a maximum cache size in terms of memory or entry count, which would trigger the eviction process. This way, you can maintain a balance between memory consumption and the freshness of the data. Additionally, consider implementing a hybrid approach where entries that are nearing their TTL are prioritized for eviction, ensuring that stale data is removed before it expires.