Weather Reporting System provides users with current weather information for a specified location.
Users will access both from web and mobile application
The information provided is:
The system allows to query for an specific location (client app can provide current user location with geolocation, or a different one)
10.000 cities all over the world (with population over 100.000) will be supported
Users can store prefered locations. This is done in client application using local storage, no server stored information.
An external weather service is responsible for providing the current information and forecasts. It provides information updates with different frequencies:
For a global user base, multiple langages and localized units or measure will be available. This will be handled in customer application.
Performance
For good user experience the information has to be provided fast, with low latency, in les than 100ms
Availability
The system must be highly available for users to trust it and repeatedly come back because it's a free service financed with adds.
Scalability
Initially figures: 100.000 daily users with 5 mean requests per day and peak 15 RPS
The system can be scalable to support significan increase, 20x, in 3 years
Security
No login nor specific security measures as no sensitive information or PII is managed.
Reliability
No data loss in case of hw / sw problems. Information should be available.
Initially figures: 100.000 daily users with 5 mean requests per day and peak 15 RPS
The system can be scalable to support significan increase, 20x, in 3 years: 2.000.000 daily users with 5 mean requests per day and peak 300 RPS
Current information ~ 45B
Total storage: 45B * 10.000 * 1,2 ~ 0,5 MB
24 h forecast ~ 425B
Total storage: 425B * 10.000 * 1,2 ~ 5 MB
7 day forecast ~ 300B
Total storage: 300B * 10.000 * 1,2 ~ 3,5 MB
Define what APIs are expected from the system...
GET /cities/{city_code}/current-weather.json
Returns a JSON with the current weather for the providied city.
GET /cities/{city_code}/24h-forecast.json
Returns a JSON with the 24 hours weather forecast for the providied city.
GET /cities/{city_code}/7d-forecast.json
Returns a JSON with the 7 days weather forecast for the providied city.
All of them will return an HTTP 404 Not found error in case of a non existing city.
For city codes, a similar policy of OpenWeatherMap City IDs will be used: "{CityName}-{ISO 3166-1 alpha-2 country code}". The city name without spaces. Example: "NewYork-USE"
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
The data managed by the application is quite static and limited so S3 will be used to store the JSON information as it will be served.
Main components:
Converts hostname to IP redirectingo to the closest CDN server to the user.
Weather information is static content that is updated at different frequencies.
For efficiency, reducing latency, scalability and high availability, the CDN will be serving and caching the information that is stored in S3 bucket once received.
Will store JSON files with the weather information.
Each file will have HTTP headers configured, for example Cache-Control , to manage CDN caching policies.
It receives and stores forcast information from the weather provider.
Thre will be a topic for each type of information:
3 microservices, one per Kafka topic, are in charghe of reading forecast information, format data and updating S3 with the data and cache control headers.
They run in a Kubernetes cluster.
Gather metrics from other systems to provide:
The information is available in the HDL Flow diagrams and in the sequence diagrams:
This flow describes how new weather data from the provider is ingested, processed, and stored in the system.
WIP ->> KC: Publish current weather eventP ->> KC: Consume weather eventP ->> P: Process & format weather dataP ->> S3: Write updated weather JSONThis flow details how a user retrieves current weather information for a city/location, including how the system leverages CDN caching for performance.
U ->> C: Search weather for city/locationC ->> DNS: Resolve weather service URLDNS -->> C: Return CDN endpointC ->> CDN: GET /cities/{city_code}/current-weather.jsonCDN -->> C: Return cached weather JSONCDN ->> S3: Fetch JSON fileS3 -->> CDN: Return weather JSONCDN -->> C: Return fresh weather JSONC -->> U: Show current weatherThere will be 3 topics, one per type of information:
The partition key is the city identifier.
In order to quicly process burst of received weather information, and taking into account that:
Confluent Parallel Consumer will be used with unordered processing. This allows to have more parallel processing threadns than paartitions.
There will be 3 microservices, one for each topic.
The number of threads / pods will depend on the topic. For example, for current weather information that is published every 5 minutes we have the goal to process them in 5 secondes.
In order to process 10.000 messages in 5 seconds, and assuming an average of 75 ms to process a message we will need 150 threads. For it we'll deploy 3 pods with 50 processing threads in parallel.
An important point for optimizing CDN usage and reducing S3 queries is caching configuration.
The following HTTP headers will be defined for elements in the buckets:
Configurations for a tradeoff between serving fresh data and costs:
The number of messages to process is not very high: generally burst of 10.000 per topic. A RabbitMQ could be used taking into account those figures with no big latency. Also, RabbitMQ at least one delivery policy is fine as data can be processed multiple once without side efects.
A Kafka Cluster is selected for weather information streaming for the following reasons:
As explained previously caching configuration has been done for a tradeoff between serving fresh data and costs
Initially it was considered to use Webervers or even microservices with a Redis chace. Even dough it could provide more fresh data for current weather info, it adds costs and complexity. The CDN is a good enough option.
Try to discuss as many failure scenarios/bottlenecks as possible.
Kafka and Weather events processor MS are points of failure. For achieving high availability:
Will be configured with 3 replicas in 3 diferent availability zones. This ensures high availability, fault tolerance and data durability.
The microservices will be run in a Kubernetes Clusters with 3 nodes in different availability zones to ensure high availability and fault tolerance.
The service provide haigh availability and is prepared to handle load spikes.
More cities can be included. Kafka is ready to support much more ones, and only Weather events processor MS needs to be scaled accoringly to proces the new load.
Functional improvements can be done to include forecast animated maps in images. They could also be stored in S3 bucket and served through the CDN.