A backend platform for collecting, storing, and analyzing weather data across multiple cities using Open-Meteo API. It features an ETL pipeline, RESTful API, PostgreSQL storage, and Kubernetes deployment.
- Clone the Repository
git clone https://github.com/orenisabella/weather-analytics.git
cd weather-analytics- Create Environment File
Create a .env file in the project root with:
PGHOST=host.docker.internal
PGPORT=5432
PGUSER=weather_user
PGPASSWORD=weather_pass
PGDATABASE=weather_db- Initialize Database (first time only)
Make sure PostgreSQL is running, then run:
npx ts-node-dev src/db/init.ts- Install Dependencies
npm installnpm run etlnpm run startServer will be available at: http://localhost:3000
Stores current or historical weather observations.
| Column | Type | Description |
|---|---|---|
| city | TEXT | Name of the city |
| temperature | REAL | Temperature in Celsius |
| wind_speed | REAL | Wind speed in km/h |
| wind_direction | REAL | Wind direction in degrees |
| timestamp | TIMESTAMP | Time the data was recorded |
| Primary Key: (city, timestamp) |
Stores alert entries based on defined thresholds (temp > 35°C or wind > 50km/h).
| Column | Type | Description |
|---|---|---|
| id | SERIAL | Auto-incremented ID (Primary Key) |
| city | TEXT | City where the alert was triggered |
| type | TEXT | Type of alert |
| value | REAL | Value that triggered the alert |
| timestamp | TIMESTAMP | Time the alert was triggered |
Get weather data for a city in a time range:
GET /weather?city=Tel%20Aviv&from=2025-04-14T00:00:00&to=2025-04-15T00:00:00
Get alerts by city, type, and time:
GET /alerts?city=London&type=High%20Temperature&from=2025-04-14T00:00:00
Used to analyze trends in weather data.
GET /trends?metric=avg_temp&from=2025-04-10
GET /trends?metric=max_wind&from=2025-04-01
GET /trends?metric=daily_avg_temp&from=2025-04-01&city=Tel%20Aviv
GET /trends?metric=daily_max_temp&from=2025-04-01&city=Tel%20Aviv
- Start Minikube
minikube start- Deploy Services
kubectl apply -f k8s/postgres-deployment.yaml
kubectl apply -f k8s/postgres-service.yaml
kubectl apply -f k8s/api-deployment.yaml
kubectl apply -f k8s/api-service.yaml- Access the API
kubectl port-forward service/weather-api 3000:3000Then visit http://localhost:3000
Both services have public Docker images hosted at:
You can pull them with:
docker pull orenisabella/weather-api
docker pull orenisabella/weather-etl- Used to fetch current weather snapshot for a city.
- Fast, simple, ideal for hourly collection.
- Returns one object (latest temperature, wind, etc.).
- Used to backfill historical data if the ETL missed hours.
- Loops over hourly data from Open-Meteo.
- Returns a list of hourly records from
fromtonow.
The system chooses between them based on whether there's a time gap since the last recorded weather entry.
Things I would do to improve scalability and performance:
- Add indexes on
timestamp,city, andtype. - Consider materialized views for heavy aggregation metrics like
daily_avg_temp. - Introduce pagination to all endpoints.
- Use Redis caching for repeated queries.
- Use async queues or schedulers (e.g., CronJob) for large city lists.
- Optionally, break alert logic into city-specific configs stored in DB.