Detailed Component Design
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
- CDN, Cache and RDB serve data to the application. CDN can be deployed at the nearest locations and stores the hottest weather data. For instance, New York City in the next 7 days. If a cache miss, we got to Cache. Many cache services can be used, like Redis. We can configure a TTL to hourly or daily depending on the use case or cities. An LRU eviciton plan should be better as users wouldn't access old weather data most of the time. Cache needs to be deployed in clusters, for instance a Redis cluster, data needs to be persisted, and syn betwee nodes need to be handled. RDB needs to have read-write replicas, data needs to be persisted. Data sharding should also be implemented as data grows. Consistent hashing is a good technique for this task, it makes horizontal scaling easily handled. Virtual nodes on top of that can minimize distruptions on adding or removing nodes.
- When a cache miss occures, it goes to read from RDB, then write back to cache. When an update event occurs, RDB pushes an event to Cache that invalidates the data entry.
- Location service, Weather service are stateless services, they are deployed in clusters and load balanced. They should be easily scaled across AZs.
- Weather data is a time-series data, thus a time-series database would be helpful for queriing, or act as a cache layer. This may overlap with #1, depending on implementation or product design. Time-series database like Influx can be more beneficial in certain cases. Each weather station stores data per second or per microsecond, they aggregate data and push to the main influxdb per minute.
- Push service waits events from event queue and push to certain users.