Giter VIP home page Giter VIP logo

dcard-pre-test-leader-board's Introduction

Getting Started

Development Environment

  • Go version go1.17.8 darwin/amd64
  • Redis version 6.2.7

Start the services

$ docker run --name some-redis -p 6379:6379 -d redis:6.2.7
$ go run ./service/api
$ go run ./service/cron

Endpoints

  • curl -X GET http://localhost/api/v1/leaderboard
  • curl -X POST -H "Content-Type:application/json" -H "ClientId: clientid" http://localhost/api/v1/score -d '{"score": 87.7}'

Notes

  • 使用 gin framework 建立 API 配合 Redis Sorted Set 作為 storage
    • Sorted Set 有天然的 unique 效果一個 client 只能建立一個 score
    • 若有複雜的計算邏輯再考慮改用 RDS + Redis (快取)
  • nice to have
    • 清除 leaderboard,目前是依照 cron 啟動時間每 10 分鐘清除一次
      • 可以考慮設定 20 分鐘以上的預設 TTL 避免 cron 失效,若 redis 被塞滿影響到其他 record 被清掉
      • 設定成整點開始計算 10 分鐘(00, 10, 20, ...)使用者比較能預期紀錄被清除的時間
    • redis config (password, port, db...) 目前是寫在 code 裡面,抽出 config 日後比較好維護
    • 執行 service 目前需要自行安裝 golang 環境以及編譯,包成 docker + makefile 體驗跟維護性會比較好一些

dcard-pre-test-leader-board's People

Contributors

gaga5lala avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.