All Projects → tim-hub → sanic-currency-exchange-rates-api

tim-hub / sanic-currency-exchange-rates-api

Licence: MIT license
This is a self hosted, free, open source Python Currency Exchange Rate API fork.

Programming Languages

python
139335 projects - #7 most used programming language
javascript
184084 projects - #8 most used programming language
Dockerfile
14818 projects
shell
77523 projects

Projects that are alternatives of or similar to sanic-currency-exchange-rates-api

vbo365-rest
Unofficial Self-Service Web Portal for Veeam Backup for Microsoft Office 365
Stars: ✭ 44 (+120%)
Mutual labels:  exchange, restful-api
vbo365-rest-self-service
Unofficial Self-Service Web Portal for Veeam Backup for Microsoft Office 365
Stars: ✭ 24 (+20%)
Mutual labels:  exchange, restful-api
FeedSDK
Java SDK for downloading large gzipped (tsv) item feed files and applying filters for curation
Stars: ✭ 20 (+0%)
Mutual labels:  restful-api
huobi Cpp
C++ SDK for Huobi Spot API
Stars: ✭ 56 (+180%)
Mutual labels:  exchange
swagger-brake
Swagger contract checker for breaking API changes
Stars: ✭ 49 (+145%)
Mutual labels:  restful-api
rack-cargo
🚚 Batch requests for Rack apps (works with Rails, Sinatra, etc)
Stars: ✭ 17 (-15%)
Mutual labels:  restful-api
Mida
The open-source and cross-platform trading framework
Stars: ✭ 263 (+1215%)
Mutual labels:  exchange
airad
Beego based Restful API service
Stars: ✭ 63 (+215%)
Mutual labels:  restful-api
symfony-todo-backend
This is the result of all the videos that were created in the series that i published on the playlist. LINK BELOW
Stars: ✭ 172 (+760%)
Mutual labels:  restful-api
serverless-rest-api
Building RESTful Web APIs with Firebase Cloud Function, Firestore, Express and TypeScript
Stars: ✭ 103 (+415%)
Mutual labels:  restful-api
papermerge-core
Papermerge RESTful backend structured as reusable Django app
Stars: ✭ 103 (+415%)
Mutual labels:  restful-api
HttpServerLite
TCP-based simple HTTP and HTTPS server, written in C#.
Stars: ✭ 44 (+120%)
Mutual labels:  restful-api
djburger
Framework for safe and maintainable web-projects.
Stars: ✭ 75 (+275%)
Mutual labels:  restful-api
gorest
Go RESTful API starter kit with Gin, JWT, GORM (MySQL, PostgreSQL, SQLite), Redis, Mongo, 2FA, email verification, password recovery
Stars: ✭ 135 (+575%)
Mutual labels:  restful-api
public
BitDust project source codes : official Public Git repository (mirror on GitHub) : https://bitdust.io
Stars: ✭ 19 (-5%)
Mutual labels:  restful-api
node-ews
A simple JSON wrapper for the Exchange Web Services (EWS) SOAP API.
Stars: ✭ 114 (+470%)
Mutual labels:  exchange
springboot-rest-api-angularjs-https
REST API https with Spring Boot and Angular JS. Use MySQL, Hibernate and Spring Security.
Stars: ✭ 38 (+90%)
Mutual labels:  restful-api
coincube
A Python/Vue.js crypto portfolio management and trade automation program with support for 10 exchanges.
Stars: ✭ 85 (+325%)
Mutual labels:  exchange
software-systems-architecture
A collection of descriptions of the architecture that various systems use.
Stars: ✭ 24 (+20%)
Mutual labels:  restful-api
apex-rest-route
A simple framework for building Restful API on Salesforce
Stars: ✭ 75 (+275%)
Mutual labels:  restful-api

Migrate Sanic Currency Exchange Rates Api to Use Redis Stack @Redis Hackathon

Use Redis Stack (RedisJson) to replace Postgres as main storage, plus some refactoring

stack change

How it works

How the data is stored:

The data is store as a document, for each day of the currency rates.

{
   "2020-01-01": {
      "USD": 1,
      "EUR": 1.1,
      "AUD": 0.97
   }
}

How the data is accessed:

In python codes, the data is accessed through a simple get

r.json().get('2020-01-01')

Performance Benchmarks

postgres performance redis json performance

Load test is used here to measure the performance.

  • same Machine (my personal macbook laptop)
  • same spec for DB
    • 10GB Volume
    • Same ARM64 Instance

The 2 key results here are iterations (higher is better) and iteration_duration(avg)(lower is better)

Fact Postgres Redis Stack
Iterations 25.26/s 5.52/s
Iteration Duration 560.15ms 5.53s

This performance benchmark is surprising to myself as well, Redis as a well performanced DB, in most of time, it give a very good result of performance.

In sum, this performance compare may not be objective, the reasons behind it requires more researching. These are some potential reasons I assume,

1.Min Specs for different DB are difference, even the spec for Postgres and Redis Stack here are the same, but their min spec requirements may be different.

  • Postgres: 1 GHz processor. 2 GB of RAM. 512 MB of HDD.
  • Redis: 2.6GHz(2 CPUs), 4 GB of Ram, 10 GD of HDD (Redis Stack supposed to be higher)

2.Decimal in Python as a class could not be saved directly as a JSON attribute in RedisJSOM, so it was stores as string, and it will be converted to Decimal when read. This may slow the APP down.

3.Query was not used (RedisSearch) was not used, so when query history data, a loop of GET are sent to DB, which is not efficient

In sum, this comparing result doesn't tell which is better between Postgres and RedisJSON, it only says that at current stage, at current DB Instance spec, for this API, postgres gives better performance, and the way of Decimal Convert and Loop of Get in Application level slows the app too. (If anyone knows better about Redis to solve these problems, please let me know). So this comparing seems not very fair.

How to run it locally?

Prerequisites

  • python 3.10
  • poetry >1.0
  • redis stack, please make sure you have a remote Redis Instance running, feel free to get one free from Redis Stack database in the cloud.
  • docker 20.10.xx (optional)

Local installation and development

Local Python App Development

  1. clone the repo git clone https://github.com/tim-hub/sanic-currency-exchange-rates-api.git
  2. export REDIS_URL = 'redis://localhost:6379' (use your own redis stack url)
  3. export USE_REDIS = 1
  4. poetry install
  5. poetry run python src/main.py

Through Docker

docker build -t rate-api . && docker run --name rate-api -t -i -e REDIS_URL=redis://your-remote-redis:6379 -e USE_REDIS=1 rate-api

or

Use a docker image.

docker run --name rate-api -p 8000:8000 -e REDIS_URL=redis://your-remote-redis:6379 -e USE_REDIS=1  ghcr.io/tim-hub/sanic-currency-exchange-rates-api:v2.3.0

Others

Deployment

This app is wrapped in a docker container, so it could be deployer to any platform (which supports docker), From AWS, Heroku to K8s,

the only requirements for it are 2 environment variables.

  • REDIS_URL
  • USE_REDIS

For example run in local machine:

docker run --name rate-api -p 8000:8000 -e REDIS_URL=redis://your-remote-redis:6379 -e USE_REDIS=1  ghcr.io/tim-hub/sanic-currency-exchange-rates-api:v2.3.0

More Information about Redis Stack

Here some resources to help you quickly get started using Redis Stack. If you still have questions, feel free to ask them in the Redis Discord or on Twitter.

Getting Started

  1. Sign up for a free Redis Cloud account using this link and use the Redis Stack database in the cloud.
  2. Based on the language/framework you want to use, you will find the following client libraries:

The above videos and guides should be enough to get you started in your desired language/framework. From there you can expand and develop your app. Use the resources below to help guide you further:

  1. Developer Hub - The main developer page for Redis, where you can find information on building using Redis with sample projects, guides, and tutorials.
  2. Redis Stack getting started page - Lists all the Redis Stack features. From there you can find relevant docs and tutorials for all the capabilities of Redis Stack.
  3. Redis Rediscover - Provides use-cases for Redis as well as real-world examples and educational material
  4. RedisInsight - Desktop GUI tool - Use this to connect to Redis to visually see the data. It also has a CLI inside it that lets you send Redis CLI commands. It also has a profiler so you can see commands that are run on your Redis instance in real-time
  5. Youtube Videos
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].