Skip to content

This is a simple service that converts currency using the Currency API.

License

Notifications You must be signed in to change notification settings

edmarfelipe/currency-service

Repository files navigation

Currency Service

build codecov Go Report Card

Description

This is a simple service that converts currency using the Currency API.

Table of Contents

Overview

Architecture

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")
Loading

Caching strategy

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
    
Loading

Installing

To work with this project, you need to have installed:

Usage

Running the project

docker-compose up -d

Building the project

make build

Running the tests

make test

REST API

Open API Definition

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

Project Key Features

  • 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

About

This is a simple service that converts currency using the Currency API.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published