sboffer v1.4.1
flex-offer
Version
See package.json for version
About
flex-offer is a service that provides data to website and apps for the following betting products:
- sports
- lotto
- virtuals As well as all backend data that is needed on the frontend, as list of shops, lotto statistics etc...
Documentation
//TODO
Technologies used
Writen in node.js, uses mongo.db as storage, express and socket.io as external channels, kafka as data provider, ETCD3 as a config provider
How does it work
Service has multiple receivers, one or more per product located in lib/ folder. For example lotto uses one receiver which on receving packet from kafka lotto topic emits lotto packet to all web socket subscribed clients and saves lotto to mongodb. These receivers also worry about handling the old data (deletion and management).
Service uses express https servers (express) and web sockets (socket.io). Web (REST) providers reside in objects/ folder and have public methods for fetching offer by provided parameters.
For sport as there is too much data flex-offer provides in-memory offer of scaled down match data and after filtering this data by request it then provides matches from mongo.db. Also sport does not provide names inside match data as it is provided by special tree handling.
Flex-offer provides live sport data and it has dinamic number of workers (provided in config file) specialy designed to handle workload of importing and processing live matches.
All data that is older than one month is deleted.
Hardware prerequisites
Based on the number of cores we recomend 2GB of ram per core. We do not recommend machines larger than 6 cores as worker statistics could be an overhead.
Scaling
Each instance scales based on number of cores available to the machine. Each core is it's own worker with it's own memory for sport and provides all the REST connectors for all products. Scaling to provide more instances to clients is horizontal.
Getting Started
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.
Prerequisites and dependecies
If not using local config file ETCD3 certificates, username, password and enviroment is needed to start the service
flex-offer uses private npm packages:
@leapbit/lb-node-metrics
For versioning we use 'appversion':
npm install appversion -g
Configuration
Either create config.js local file or provide ETCD instance with the following key setup:
/offer/configuration/{env}/services/flex-offer
In which {env} is env variable provided in arguments (env=dev ...)
Configuration file or etcd key should provide following data:
{
"port": 9000, //port on which the web and socket service will run
"metrics": {
"port": 10000 //port on which metrics will be exposed
},
"sportPorts": [
9001 //additional sport workers and ports for clients (for production 20 or more is needed, for example from 9001 - 9021)
],
"isCluster": true, //tell the metrics that we will be using clustered metrics
//mongodb configuration, beware of user rights and dbname and replica name
"mongodb": {
"location": "mongodb://offer:password@server1.server.loc,server2.server.loc,server3.server.loc/dbname?replicaSet=replicasetname",
"dbname": "dbname"
},
//kafka topic setup
"kafka": {
"url": "kafka.demobet.lan",
"lottotopic": "dev_offer_lotto_2",
"lottostatstopic": "dev_offer_lotto_statistics_2",
"sporttopic": "offer_sport_2",
"sportmetatopic": "offer_meta_2",
"specialstopic": "dev_specialsfeed_2",
"vhorsetopic": "dev_offer_vhorse_2",
"lottodisplaytopic": "dev_offer_lottodisplay"
},
//languages offer server provides
"languages": [
"en-GB",
"hr-HR"
],
//default language
"defaultLangCode": "hr-HR",
//slack hook for reporting errors
"slack": {
"url": "https://hooks.slack.com/services/...",
"channel": "mon_offer_serv_ng_st"
},
//which products will be provided by this instance
"products": {
"sport": true,
"lotto": true,
"lottostats": true,
"specials": true,
"shops": false,
"vhorse": true,
"lottodisplay": true
}
}
Installing
Enter the project directory and install all the dependecies with:
npm install
Running
For local config file:
node app.js config=./config.js env=dev
For etcd config
node app.js etcd_cluster=etcd01.demobet.lan:2379,etcd02.demobet.lan:2379,etcd03.demobet.lan:2379 etcd_user=offer etcd_pass=xxxxx sys_ca=../etcd_cert/ca.pem sys_crt=../etcd_cert/client.demobet.lan.pem sys_key=../etcd_cert/client.demobet.lan-key.pem env=dev
If you wan't to use a watcher in developing phase you can use "nodemon", install it globally with:
npm install -g nodemon
and run the service with it (using local or etcd config):
nodemon --watch . .....
Metrics
Service exposes prometheus compatible metrics on :metricsport/metrics and can be picked up automatically.
Running the tests
We provide another package "flex-admin-tools" which have tests for complete flex-admin project.
Deployment
Deployment is done with the CI gitlab.
Built With
- Node.js - Language used
- Express - The web framework used
- Apache Kafka - Messaging service
- Socket.io - Web socket implementation
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Authors
- Dario Filkovic
- Marko Vrbancic
License
This project is licensed under the Trade Secret License
Acknowledgments
- None
5 years ago