Problem Statement
Build a RESTful API for real-time transaction statistics calculation.
The service must maintain statistics for transactions that occurred
within the last 60 seconds and provide these statistics efficiently.
Requirements
API Endpoints
1. POST /transactions: Create a new transaction.
Request Body:
{
"amount": "12.34",
"timestamp": "2025-12-26T12:30:45.123Z"
}
Field Specifications:
- amount - Transaction amount as a string with decimal precision
- timestamp - Transaction timestamp in ISO 8601 format
2. GET /statistics: Return statistics based on transactions that occurred within the last 60
seconds.
Response Body:
{
"sum": "1500.50",
"avg": "150.05",
"max": "500.00",
"min": "10.50",
"count": 10
}
Response Code:
- 200 OK - Successfully returned statistics
All monetary values must be returned as strings with exactly 2 decimal
places.
3. DELETE /transactions: Delete all transactions.
Response Code:
- 204 No Content - All transactions successfully deleted
Performance Requirements (Optimal)
- POST /transactions must execute in O(1) time complexity
- GET /statistics must execute in O(1) time complexity (constant time)
- DELETE /transactions must execute in O(1) time complexity
- The API must handle high concurrency with thread-safe operations
Technology Stack
- Java 8+
Deliverables
1. Fully functional REST API with all three endpoints
2. Thread-safe implementation supporting high concurrency
3. Unit tests covering core business logic
4. Integration tests validating API contracts and edge cases
5. Proper exception handling with correct HTTP status codes
6. Clean, maintainable code following SOLID principles
Please share your thoughts.
Build a RESTful API for real-time transaction statistics calculation.
The service must maintain statistics for transactions that occurred
within the last 60 seconds and provide these statistics efficiently.
Requirements
API Endpoints
1. POST /transactions: Create a new transaction.
Request Body:
{
"amount": "12.34",
"timestamp": "2025-12-26T12:30:45.123Z"
}
Field Specifications:
- amount - Transaction amount as a string with decimal precision
- timestamp - Transaction timestamp in ISO 8601 format
2. GET /statistics: Return statistics based on transactions that occurred within the last 60
seconds.
Response Body:
{
"sum": "1500.50",
"avg": "150.05",
"max": "500.00",
"min": "10.50",
"count": 10
}
Response Code:
- 200 OK - Successfully returned statistics
All monetary values must be returned as strings with exactly 2 decimal
places.
3. DELETE /transactions: Delete all transactions.
Response Code:
- 204 No Content - All transactions successfully deleted
Performance Requirements (Optimal)
- POST /transactions must execute in O(1) time complexity
- GET /statistics must execute in O(1) time complexity (constant time)
- DELETE /transactions must execute in O(1) time complexity
- The API must handle high concurrency with thread-safe operations
Technology Stack
- Java 8+
Deliverables
1. Fully functional REST API with all three endpoints
2. Thread-safe implementation supporting high concurrency
3. Unit tests covering core business logic
4. Integration tests validating API contracts and edge cases
5. Proper exception handling with correct HTTP status codes
6. Clean, maintainable code following SOLID principles
Please share your thoughts.
RSS Feed