1. Service Implementation with Smart Integration Tests
Goal: Implement a simple service that greets a user by name, with robust integration test coverage.
Requirements:
A REST endpoint that returns "Hello, !"
Name can be received either as:
Path variable (e.g., /hello/John)
Or query parameter (e.g., /hello?name=John)
If the name is missing, return an appropriate error (400 Bad Request)
Write integration tests that:
Generate dynamic names (e.g., using UUID/random names)
Test both input methods (path/query)
Ensure the response is correct even when name is missing
2. Add Time-Based Blocking Logic (Smartly Testable)
Goal: Add a rule to block the service between 14:00 and 16:00, in a way that can be mocked and tested reliably.
â
Requirements:
When the request comes between 14:00â16:00 â return 503 Service Unavailable
Do NOT use LocalTime.now() directly inside logic. Instead:
Abstract time-checking logic into a TimeGatekeeper interface with a method like boolean isAllowedNow()
Implement a default version that checks current time
In tests:
Mock the TimeGatekeeper to simulate allowed/blocked times
Ensure greeting still works in tests (time-blocking shouldnât interfere with unrelated test logic) and you shold not mock the clock
â
Also:
Write a unit test for TimeGatekeeper itself
Integration tests should pass even if current system time is in blocked range
3. System Design Question: OCR Over Millions of Images in S3
Scenario:
You have:
A large S3 bucket s3://images-a with millions of images (4â5MB each)
A single machine with limited memory, CPU, and disk
Goal: Run OCR on all images and save results to a second bucket s3://images-b
Constraints: Maximize throughput, support failure recovery, and enable monitoring