This is an API using Spring Boot, using Maven for compiling and building the application. It provides a restful service and documented with Swagger.
The main use case for this API is to calculate real time statistic from the last 60 seconds. There will be two APIs, one of them is called every time a transaction is made. It is also the sole input of this rest API. The other one returns the statistic based of the transactions of the last 60.
Every Time a new transaction happened, this endpoint will be called.
Where:
-
Amount is double specifying transaction amount
-
Timestamp is epoch in millis in UTC time zone specifying transaction time
POST /api/transactions HTTP/1.1 Content-Type: application/json
{
"amount": 12.3,
"timestamp": 1478192204000
}
This is the main endpoint of this task, this endpoint have to execute in constant time and memory (O(1)). It returns the statistic based on the transactions which happened in the last 60 seconds.
HTTP/1.1 200 OK Content-Type: application/json
{ "sum": 12.3, "avg": 12.3, "max": 12.3, "min": 12.3, "count": 1 }
Where:
-
sum is a double specifying the total sum of transaction value in the last 60 seconds
-
avg is a double specifying the average amount of transaction value in the last 60 seconds
-
max is a double specifying single highest transaction value in the last 60 seconds
-
min is a double specifying single lowest transaction value in the last 60 seconds
-
count is a long specifying the total number of transactions happened in the last 60 seconds