This is a simple service that converts currency using the Currency API.
C4Container
Container_Ext(client, "Clients", "Web App, Mobile, Service, etc", "External client that uses the API")
Boundary(c1, "Currency Service") {
Container(api, "API Application", "Container: Go", "API that converts currency")
ContainerDb(cache, "Cache", "Container: Redis", "Stores the currency rates")
}
System_Ext(currency_api, "Currency API", "External API that provides the currency rates")
Rel(client, api, "Uses", "sync, JSON/HTTPS")
Rel_Back(cache, api, "Reads from and writes to", "sync, TCP/6379")
Rel(api, currency_api, "Reads from", "sync, JSON/HTTPS")
UpdateRelStyle(cache, api,$textColor="#ced4da", $lineColor="#ced4da", $offsetX="-50", $offsetY="25")
UpdateRelStyle(api, currency_api,$textColor="#ced4da", $lineColor="#ced4da", $offsetX="10", $offsetY="-30")
UpdateRelStyle(client, api, $textColor="#ced4da", $lineColor="#ced4da", $offsetX="5", $offsetY="-40")
We want to always get from the cache as match as possible, to do so, we will update the cache in the background, while we return the value from the cache.
flowchart TD
NewRequest((New Request)) -->
IsOnCache{Is in the cache?}
IsAsync{Is Async?}
IsCacheFinishing{Cache is almost expire?}
Request[Request from API]
Return[Return value]
IsOnCache -->|Yes| IsCacheFinishing
IsCacheFinishing-.->|Yes|Request
IsCacheFinishing-->|No|Return
IsCacheFinishing-->|Yes|Return
IsOnCache -->|No| Request
Request--> SaveInCache
SaveInCache[Save in the cache] --> IsAsync
IsAsync -->|No|Return
IsAsync -->|Yes|End
To work with this project, you need to have installed:
docker-compose up -d
make build
make test
Description | Verb | Path |
---|---|---|
Convert Value | GET | /api/convert/{currency}/{value} |
Metrics | GET | /api/metrics |
Ready | GET | /api/ready |
Example of request:
curl --request GET \
--url http://localhost:3000/api/convert/BRL/543.34
- Structure Logging with Request ID
- Graceful Shutdown
- Healthcheck route that waits for the startup to finish
- Usage of Redis Client-side Caching
- Prometheus metrics with latency and request count
- Tiny docker image with distroless base image