Golang Caching Microservice (bequant.io test project to get hired)

bequant test project

How to use:

Simply type docker-compose up -d --build db warden distributor in terminal while in project's directory. MySQL, Warden (updates data) and Distributor (provides API) will be started. Access API at localhost:8080.

Before running, create .env file based on example.env. This is the way to configure the service.

API Description:

One handle: /price

Two params, both required: ?fsyms=CURRENCY,...&tsyms=CURRENCY,..., where CURRENCY is a currency symbol (USDT, for example)

Example:

Curl Request:
curl 127.0.0.1:8080/price?fsyms=BTC&tsyms=USD

JSON Response:
{
  "RAW": {
    "BTC": {
      "USD": {
        "CHANGE24HOUR": -13.25,
        "CHANGEPCT24HOUR": -0.18152873223073468,
        "OPEN24HOUR": 7299.12,
        "VOLUME24HOUR": 47600.120073200706,
        "VOLUME24HOURTO": 348033250.4911315,
        "LOW24HOUR": 7197.22,
        "HIGH24HOUR": 7426.64,
        "PRICE": 7285.87,
        "LASTUPDATE": 1586433196,
        "SUPPLY": 18313937,
        "MKTCAP": 133432964170.19
      }
    }
  },
  "DISPLAY": {
    "BTC": {
      "USD": {
        "CHANGE24HOUR": "$ -13.25",
        "CHANGEPCT24HOUR": "-0.18",
        "OPEN24HOUR": "$ 7,299.12",
        "VOLUME24HOUR": "Ƀ 47,600.1",
        "VOLUME24HOURTO": "$ 348,033,250.5",
        "HIGH24HOUR": "$ 7,426.64",
        "PRICE": "$ 7,285.87",
        "FROMSYMBOL": "Ƀ",
        "TOSYMBOL": "$",
        "LASTUPDATE": "Just now",
        "SUPPLY": "Ƀ 18,313,937.0",
        "MKTCAP": "$ 133.43 B"
      }
    }
  }
}

Stack:

  • Golang
  • MySQL
  • Docker

Task:

Make an API cacher, I would say. We have Cryptocompare API and the task is to make microservice which stores API answers and provides it's own API to get this data.

Load testing

> ab -n 100000 -c 10 'http://localhost:8080/price?fsyms=BTC&tsyms=USD'

This is ApacheBench, Version 2.3 <$Revision: 1879490 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
Completed 40000 requests
Completed 50000 requests
Completed 60000 requests
Completed 70000 requests
Completed 80000 requests
Completed 90000 requests
Completed 100000 requests
Finished 100000 requests


Server Software:        
Server Hostname:        localhost
Server Port:            8080

Document Path:          /price?fsyms=BTC&tsyms=USD
Document Length:        584 bytes

Concurrency Level:      10
Time taken for tests:   9.498 seconds
Complete requests:      100000
Failed requests:        0
Total transferred:      69300000 bytes
HTML transferred:       58400000 bytes
Requests per second:    10528.45 [#/sec] (mean)
Time per request:       0.950 [ms] (mean)
Time per request:       0.095 [ms] (mean, across all concurrent requests)
Transfer rate:          7125.21 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     0    1   0.3      1       9
Waiting:        0    1   0.3      1       8
Total:          0    1   0.3      1       9

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      2
  99%      2
 100%      9 (longest request)

Requirements:

  • REST API
  • If Cryptocompare is not accessible service must return data from database via own API (It's the purpose, or service should act just as gateway if API is accessible?)
  • Data in response must be fresh (realtime). 2-3 minutes discrepancy is ok. (Again, realtime means being a gateway? I'll just do continuous caching)
  • Currency pairs should be configurable.
  • MySQL parameters should be configurable.
  • Service must store data to MySQL by sheduler (rawjson is ok).
  • Service must work in background.

Not required, but appreciated:

  • WebSockets (Why? If the service can return 2-3 min old data. To discard HTTP overhead? It won't be a problem, I think)
  • Clean Architecture (Uncle Bob's?)
  • ? Scalability (Will do!) Add Caddy server proxy with Round-Robin algorithm (https://nknv.ru/caddy-load-balancing)

Cryptocompare API: https://min-api.cryptocompare.com/data/pricemultifull?fsyms=BTC&tsyms=USD,EUR

Owner
Nikita Nikonov
@RickCastle2018
Nikita Nikonov
Similar Resources

Microservice Boilerplate for Golang with gRPC and RESTful API. Multiple database and client supported

Microservice Boilerplate for Golang with gRPC and RESTful API. Multiple database and client supported

Go Microservice Starter A boilerplate for flexible Go microservice. Table of contents Features Installation Todo List Folder Structures Features: Mult

Jul 28, 2022

Kitex byte-dance internal Golang microservice RPC framework with high performance and strong scalability, customized extensions for byte internal.

Kitex byte-dance internal Golang microservice RPC framework with high performance and strong scalability, customized extensions for byte internal.

Kitex 字节跳动内部的 Golang 微服务 RPC 框架,具有高性能、强可扩展的特点,针对字节内部做了定制扩展。

Jan 9, 2023

A microservice gateway developed based on golang.With a variety of plug-ins which can be expanded by itself, plug and play. what's more,it can quickly help enterprises manage API services and improve the stability and security of API services.

A microservice gateway developed based on golang.With a variety of plug-ins which can be expanded by itself, plug and play. what's more,it can quickly help enterprises manage API services and improve the stability and security of API services.

Goku API gateway is a microservice gateway developed based on golang. It can achieve the purposes of high-performance HTTP API forwarding, multi tenant management, API access control, etc. it has a powerful custom plug-in system, which can be expanded by itself, and can quickly help enterprises manage API services and improve the stability and security of API services.

Dec 29, 2022

Microservice to manager users with golang

User Service Microservice to manager users. Assumptions & Limitations This API a

Dec 27, 2021

Golang Microservice making use of protobuf and gRPC as the underlying transport protocol.

Go-Microservices Golang Microservice making use of protobuf and gRPC as the underlying transport protocol. I will be building a generic microservice,

Jan 5, 2022

Go-rifa-microservice - Clean Architecture template for Golang services

Go-rifa-microservice - Clean Architecture template for Golang services

Test CI Go Clean template Clean Architecture template for Golang services Overvi

Sep 22, 2022

Go gRPC RabbitMQ email microservice

Go, RabbitMQ and gRPC Clean Architecture microservice 👋 👨‍💻 Full list what has been used: GRPC - gRPC RabbitMQ - RabbitMQ sqlx - Extensions to data

Dec 29, 2022

A Microservice Toolkit from The New York Times

A Microservice Toolkit from The New York Times

Gizmo Microservice Toolkit This toolkit provides packages to put together server and pubsub daemons with the following features: Standardized configur

Jan 7, 2023

Go products microservice

Golang Kafka gRPC MongoDB microservice example 👋 👨‍💻 Full list what has been used: Kafka - Kafka library in Go gRPC - gRPC echo - Web framework vip

Dec 28, 2022
Microservice - Microservice golang & nodejs
Microservice - Microservice golang & nodejs

Microservice Gabungan service dari bahasa pemograman go, nodejs Demo API ms-auth

May 21, 2022
Customer-microservice - Microservice of customer built with golang and gRPC

?? Building microservices to manage customer data using Go and gRPC Command to g

Sep 8, 2022
Targetrwe api test - This project provides the backend service for the targetrwe test application

Targetrwe-api This project provides the backend service for the targetrwe test a

Feb 15, 2022
Microservice - A sample architecture of a microservice in go

#microservice Folder structure required. service certs config config.yaml loggin

Feb 3, 2022
Trying to build an Ecommerce Microservice in Golang and Will try to make it Cloud Native - Learning Example extending the project of Nic Jackson

Golang Server Project Best Practices Dependency Injection :- In simple words, we want our functions and packages to receive the objects they depend on

Nov 28, 2022
Go microservice tutorial project using Domain Driven Design and Hexagonal Architecture!

"ToDo API" Microservice Example Introduction Welcome! ?? This is an educational repository that includes a microservice written in Go. It is used as t

Jan 4, 2023
Assignment2 - A shared project making use of microservice architecture

This project is a shared project making use of microservice architecture, API's and a simple frontend to implement a start-up new concept called EduFi. The concept combines education and financial systems to create profit from studying.

Jan 26, 2022
Kratos is a microservice-oriented governance framework implements by golang
Kratos is a microservice-oriented governance framework implements by golang

Kratos is a microservice-oriented governance framework implements by golang, which offers convenient capabilities to help you quickly build a bulletproof application from scratch.

Dec 27, 2022
Modern microservice web framework of golang
Modern microservice web framework of golang

gogo gogo is an open source, high performance RESTful api framework for the Golang programming language. It also support RPC api, which is similar to

May 23, 2022
Kratos is a microservice-oriented governance framework implements by golang,
Kratos is a microservice-oriented governance framework implements by golang,

Kratos is a microservice-oriented governance framework implements by golang, which offers convenient capabilities to help you quickly build a bulletproof application from scratch.

Dec 31, 2022