How prateek2468/interview-interview-tech-challenge-solution works
Project type and purpose
• This is a standalone, backend‐only, event-driven microservice written in Java using the Vert.x toolkit.
• It exposes HTTP endpoints to aggregate and serve weather and air-pollution data by calling the OpenWeather external API.
High-level file structure analysis
• pom.xml: Maven build and dependency management.
• src/main/java/org/lotlinx/interview
• MainVerticle.java: Bootstraps the Vert.x event loop and HTTP server on port 8080.
• Constants.java: Shared constants (port numbers, URI paths).
• handlers/interfaces/openWeatherHandler.java: Defines the contract for weather data retrieval.
• handlers/impl/OpenWeatherHandlerImpl.java: Concrete implementation that calls out to the OpenWeather API.
• handlers/impl/MainVerticleHandler.java: Orchestrates incoming HTTP requests, delegates to the appropriate handler.
• util/WebClientHelper.java: Wraps Vert.x WebClient setup for external HTTP calls.
• src/test: A minimal JUnit test (HelloTest) validates the “/hello” endpoint.
Key insights from README
• Vert.x event loop architecture.
• Endpoints: /hello (health), /getCurrentAirPollution, /weather/current.
• Aggregation style: accepts comma-separated or repeated “cities” params.
• No persistent storage; fully stateless.
Main components
a. Client(s)
• REST clients (curl, UI, other services)
b. HTTP Server (Vert.x MainVerticle)
• Listens on port 8080
c. Routing & Handlers
• MainVerticleHandler: maps incoming requests to service operations
• OpenWeatherHandlerImpl: executes business logic for weather/air-pollution calls
d. WebClientHelper + Vert.x WebClient
• Asynchronous HTTP client for external calls
e. External Service
• OpenWeather API (weather data provider)
Relationships and interactions (data flow)
1. Client sends HTTP request →
2. Vert.x MainVerticle receives on eventloop →
3. Routes to MainVerticleHandler →
4. MainVerticleHandler invokes OpenWeatherHandlerImpl →
5. OpenWeatherHandlerImpl uses WebClientHelper →
6. WebClient issues asynchronous HTTP call to OpenWeather API →
7. OpenWeather returns JSON →
8. OpenWeatherHandlerImpl processes & transforms to response format (CSV or JSON) →
9. Response written back via MainVerticle on HTTP response.
Architectural patterns & principles
• Event-driven, non-blocking I/O (Vert.x event loop).
• Clear separation of concerns:
• Verticle orchestration vs. handler interfaces vs. external-API implementation
• Dependency injection by interface (openWeatherHandler).
• Stateless design—easy to scale horizontally.
Final checklist
• Notation for asynchronous vs. synchronous calls.