Here is a simplified design diagram that explains how a stock exchange such as Nasdaq or Newyork exchange works under the hood: #developers #systemdesign

Step 1: A client places an order via the broker’s web or mobile app.

Step 2: The broker sends the order to the exchange.1/6 Stock exchange design
Step 3: The exchange client gateway performs operations such as validation, rate limiting, authentication, normalization, etc., and sends the order to the order manager.

Step 4-5: The order manager performs risk checks based on rules set by the risk manager.2/6
Step 6: Once risk checks are passed, the order manager checks if there is enough money in the wallet.

Step 7 - 9: The order is sent to the matching engine. The matching engine sends back the execution result if a match is found. 3/6
Step 10 - 14: The execution result is passed all the way back to the client.

Step M1 - M3 (market data flow): Market data, including the candlestick chart and order book, are sent to the data service for consolidation. Brokers query the data service to get the market data. 4/6
Step R1 - R2 (reporting flow): The reporter composes all the necessary reporting fields (e.g. client_id, price, quantity, order_type, filled_quantity, remaining_quantity) and writes data to the database.5/6
Please notice that steps 1 to 14 are on the critical path (the trading flow), while the market data flow and reporting flow are not. They have different latency requirements. If you have any questions or I missed anything, please leave a comment.
6/6

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Alex Xu

Alex Xu Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @alexxubyte

4 Jan
One of the most serious problems a payment system can have is to 𝐝𝐨𝐮𝐛𝐥𝐞 𝐜𝐡𝐚𝐫𝐠𝐞 𝐚 𝐜𝐮𝐬𝐭𝐨𝐦𝐞𝐫. When we design the payment system, it is important to guarantee that the payment system executes a payment order exactly-once.1/6 Image
At the first glance, exactly-once delivery seems very hard to tackle, but if we divide the problem into two parts, it is much easier to solve. An operation is executed exactly-once if:

1. It is executed at least once.
2. At the same time, it is executed at most once.2/6
We now explain how to implement at least once using retry and at most once using idempotency check.

𝐑𝐞𝐭𝐫𝐲
Occasionally, we need to retry a payment transaction due to network errors or timeout. Retry provides the at-least-once guarantee. 3/6
Read 6 tweets
3 Jan
Here is what happens when you click the Buy button on Amazon or any of your favorite shopping websites.

1. When a user clicks the “Buy” button, a payment event is generated and sent to the payment service.

2. The payment service stores the payment event in the database. 1/6 Image
3. Sometimes a single payment event may contain several payment orders. For example, you may select products from multiple sellers in a single checkout process. The payment service will call the payment executor for each payment order. 2/6
4. The payment executor stores the payment order in the database.

5. The payment executor calls an external PSP to finish the credit card payment. 3/6
Read 6 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(