Feb. 23, 2021
Introduction
It is tough experience for me to learn how to prepare for System Design. Last 12 months I have onsite interviews with Facebook, Google and Microsoft Vancouver. Facebook and Microsoft both have system design interview. I could not clear the system design interview since I do not study hard enough. Now it is time for me to learn webSocket and work on a trading system design.
WebSocket and Trading system
Here is the article I found and it is easy for me to read and learn.
Publish web socket in the experience layer -
Web socket is a communication protocol over TCP that enables bidirectional communication between client and server.
As you can see in the diagram above, the client initiate connection over WebSocket or secure WebSocket (wss), and then the server can send back messages to the client. Unline with HTTP protocol we do not need to do any pulling. Once the connection is established, the server can send as many requests as it likes.
The greatest benefit of using Web Socket instead of HTTP is performance boost as we do not need to establish a new connection. What is more, we do not need to introduce any sort of pulling mechanism.
WebSocket Connector - Exchange Rates case
We want to consume forex exchange rates and display them on our banking portal. As they are changing rapidly, we would like to keep values up to date. I have decided to expose WebSocket endpoint to stream changes to the client.
MuleSoft best practice is API-led connectivity. As a result, in our case, we have three layers. We have Banking Portal Experience API (XAPI), Banking Process API (PAPI) and Banking Forex System API (SAPI). In order to make the data flow smoothly, we will use Amazon SQS queues to exchanged data between layers – as in the diagram above.
Our system API reads exchange rates and publishes them to exchange-rates-sapi queue. Banking Process API reads values from this queue and saves them to exchange-rates-papi queue. This queue will be read by the application in the Experience layer. The Banking Portal XAPI broadcast exchange rates to open web sockets.
When the client initiates a web socket connection, it must decide the primary currency. In other words, if exchange rates should be calculated against USD, EUR, PLN currencies.
No comments:
Post a Comment