Architecture
Building an API for low latency trading
Architecture:
Design tenets:
- We have the following main entities in the system:
- Client Application
- Backend service
- Finance exchange server
- Client application invoke the API for retrieving the account information form the server. The account information data is stored in the Nosql database (mainly Cassandra). The API key can be decrypted to extract the user id, which is a primary key in the database. Apparently, this approach is preferred compared to the use of API key as primary key since primary key generally have constraint on the number of characters.
- The order information is also stored in the Cassandra. In the flow, as the order come to the backend, it is dispatched to the exchange. After response from the exchange, it is persisted
- The securities information is saved to hdfs and open TSDB can be used to query by time
- Predictions jobs are run on the data with spark while ingesting from HDFS. Deep learning jobs can be written on Spark to predict the results
- All the micro services communicate with gRPC internally
- Aggregator service can be run on the same pod with order service
Authentication:
User is provided with the API key after subscribing to the platform which can be used for the trading
API: –
GET /v1/info – Return the user information for a given user/key
POST /v1/order – order to market
- Type – buy/sell
GET /v1/transactions – shows the transactions for the user
DELETE /v1/orders
/v1/orders/{orderID}
Cancels all the pending orders or a given order
GET /v1/assets (securities) – the prices of the securities at a given time