PORT: The port the server will run on. Defaults to 3000.REDIS_URL: The URL of the Redis server. Optional. You can use rediss://default:AVNS_MqpsAwU_giOEGIHhFto@db-caching-nyc3-68825-do-user-17971709-0.e.db.ondigitalocean.com:25061 for testing purposes.MAX_RETRY: The maximum number of retries when fetching external data. Defaults to -1. Use -1 for infinite retries. Warning: This could result in performance issues. In case of service unavailability, the server will retry indefinitely. Leading to timeouts.USE_PISCINA: Whether to use Piscina for background tasks. Defaults to false. Piscina is used to spawn workers to fetch and handle data from the API. Warning duration could be affected, response time could be slower.EXTERNAL_SOURCE_URL: The URL of the external source.DEBUG: Whether to enable debug mode. Defaults to false. Warning logging could result in performance issues.GET /:Main entry point. This endpoint will fetch data from the external source. It respond an object with the following shape:
{
"start": "2024-02-29T12:00:00Z", // The start date of the data
"end": "2024-02-29T13:00:00Z", // The end date of the data
"min": "100", // The minimum amount of the data
"max": "200", // The maximum amount of the data
"data": [{
"amount": "100", // The amount of the data
"timestamp": "2024-02-29T12:00:00Z" // The timestamp of the data
},
{
"amount": "150", // The amount of the data
"timestamp": "2024-02-29T12:30:00Z" // The timestamp of the data
},
...
]
}
Headers:
X-Checksum: The checksum of the data (only if redis is available).X-Fetched-At: The data fetch date.X-Error: The error message if any.X-Piscina: Whether Piscina is used to process data (true or false).GET /health: Health check endpoint.Returns the following object:
{
"self": "ok",
"externalSource": "ok",
"redis": "ok",
"status": "ok"
}
Possible values are:
ok: The service is healthy.error: The service is not healthy.warning: The service is not setup (only for Redis).Checks are the following:
externalSource - External source: Check if the external source is reachable.redis - Redis: Check if the Redis server is reachable.self - Self: Check if the server is running.status - Status: Check if the server is running and all services are healthy.When an error occurs, the server will retry to fetch the data at most MAX_RETRY times.
If data can not be fetched after MAX_RETRY attempts, the server will try to retrieve it from Redis cache if it's available.
If no data is found in Redis, the server will return an default object and the error will be logged.
{
"start": "-",
"end": "-",
"min": "-",
"max": "-",
"data": []
}
Error details will be sent in X-Error header.
Docker image is available on Docker Hub https://hub.docker.com/repository/docker/liryc/bitstack-assesment/general.
docker pull liryc/bitstack-assessment:latest
A live version of the service is available on http://test-1204898639.eu-west-3.elb.amazonaws.com.
It's hosted on AWS using Fargate. We have a loadbalancer in front of the service to distribute the traffic to the 2 tasks.
Resources:
Content type
Image
Digest
sha256:1ff9e5ffa…
Size
71.7 MB
Last updated
about 2 years ago
docker pull liryc/bitstack-assesment