Skip to contentমূল লেখায় যান

Case 14 · System designকেস 14 · System design

How a Stock Exchange Works

A stock exchange is where people who want to buy a share meet people who want to sell it. When you tap "buy", the exchange must check your money, put your order in a fair place in line, and find a seller, for huge numbers of orders, without ever breaking the rules of fairness. This page follows one article that designs a simple exchange, not one named exchange.

9 min read9 মিনিটে পড়া যায় · 9 sections9টি সেকশন · 1 source1টি সোর্স · updated Oct 2026আপডেট: Oct 2026

An order meets the order bookএকটা অর্ডার অর্ডার বুকের সঙ্গে মেলে

Follow one buy order to a ticket number and the order book, then move its price to see it rest or trade.একটা কেনার অর্ডারকে টিকিট নম্বর আর অর্ডার বুক পর্যন্ত অনুসরণ করুন, তারপর দাম বদলে দেখুন সেটা অপেক্ষা করে নাকি ট্রেড হয়।

2 min2 মিনিট7 steps7টি ধাপ
  • Best buy / sellসেরা কেনা / বেচা99 / 101
  • Spreadস্প্রেড2
  • Next ticketপরের টিকিট#1042
FIXFIXbrokerব্রোকারbuy 10 @ 100কেনা 10 @ 100Gatewayগেটওয়েMatchingম্যাচিংengineইঞ্জিনTradeট্রেডhistoryইতিহাসbuy · highest firstকেনা · বেশি দাম আগেsell · lowest firstবেচা · কম দাম আগে104103102610181009910985
Buy limit priceকেনার সীমা দাম

You’ll learnআপনি শিখবেন

  • What the gateway and ticket number doগেটওয়ে আর টিকিট নম্বর কী করে
  • How the book sorts buys and sellsবুক কীভাবে কেনা ও বেচা সাজায়
  • When an order trades and when it restsকখন অর্ডার ট্রেড হয়, কখন অপেক্ষা করে
  • How the spread changesস্প্রেড কীভাবে বদলায়
  • Why cancels must be fastক্যানসেল কেন দ্রুত হতে হবে

The problem in plain words

The article starts with a farmer's market Source 1সোর্স 1. Each stock is like one stall. Sellers ask for a price. Buyers look for the cheapest seller first. When a buyer offers at least what a seller asks, the two make a deal Source 1সোর্স 1. The exchange earns fees on trades, so it wants as many trades as possible Source 1সোর্স 1.

The article's design must do these jobs Source 1সোর্স 1:

  • Trade stocks only.
  • Let users place buy orders and sell orders.
  • Let users cancel an order at any time.
  • Match buyers and sellers in real time.
  • Limit how many shares one user can trade each day.
  • Publish market data (prices and trades) in real time.

The article does not give user counts or trades per second. It gives the mix of messages that most exchanges see Source 1সোর্স 1:

Message typeShare of all messages
New ordersabout 50%
Cancelsabout 40%
Executions (real trades)about 2%

This mix surprises many people. Only a tiny share of messages turns into a trade. Most of the work is adding orders and taking them back. So cancels must be just as fast as new orders.

সহজ English

The article compares an exchange to a farmer's market Source 1সোর্স 1. Each stock is one stall. Sellers ask for a price, and buyers look for the cheapest seller first. A deal happens when a buyer offers at least the price that a seller asks Source 1সোর্স 1. The exchange earns fees on trades, so it wants as many trades as possible Source 1সোর্স 1.

The design in the article must do these jobs Source 1সোর্স 1: trade only stocks, let users place buy orders and sell orders, let users cancel an order at any time, match buyers and sellers in real time, limit the number of shares that one user can trade each day, and publish market data (prices and trades) in real time.

The article gives no user counts and no trades per second. It gives the mix of messages that most exchanges see Source 1সোর্স 1: about 50% are new orders, about 40% are cancels, and about 2% are executions (real trades). Most of the work is to add orders and take them back. Thus cancels must be as fast as new orders.

বাংলা ব্যাখ্যা

Article-টি একটি exchange-কে কৃষকের বাজারের সঙ্গে তুলনা করে Source 1সোর্স 1। প্রতিটি stock যেন একটি দোকান। বিক্রেতারা একটি দাম চান, আর ক্রেতারা আগে সবচেয়ে সস্তা বিক্রেতাকে খোঁজেন। কোনো ক্রেতা যখন বিক্রেতার চাওয়া দামের সমান বা বেশি দাম দেন, তখন দুজনের মধ্যে deal হয় Source 1সোর্স 1। Exchange trade থেকে fee পায়, তাই এটি যত বেশি সম্ভব trade চায় Source 1সোর্স 1।

Article-এর design-কে এই কাজগুলো করতে হবে Source 1সোর্স 1: শুধু stock trade করা, user-দের buy order ও sell order দিতে দেওয়া, যেকোনো সময় order cancel করতে দেওয়া, real time-এ ক্রেতা ও বিক্রেতা match করা, একজন user প্রতিদিন কতগুলো share trade করতে পারবেন তার সীমা রাখা, এবং real time-এ market data (দাম ও trade) প্রকাশ করা।

Article-টি user-এর সংখ্যা বা প্রতি সেকেন্ডে trade-এর সংখ্যা দেয় না। এটি বেশিরভাগ exchange-এ আসা message-এর মিশ্রণ দেয় Source 1সোর্স 1: প্রায় 50% নতুন order, প্রায় 40% cancel, আর প্রায় 2% execution (আসল trade)। অর্থাৎ খুব কম message-ই trade-এ পরিণত হয়। বেশিরভাগ কাজ হলো order যোগ করা আর ফিরিয়ে নেওয়া। তাই cancel-কেও নতুন order-এর মতোই দ্রুত হতে হবে।

The big picture

[User app] --REST / WebSocket--> [Broker] --FIX--> [Gateway]
                                                      |
                                    +-----------------+-----------------+
                                    |                 |                 |
                              [Risk manager]      [Wallet]      [Order manager]
                                                                        |
                                                                 sequence number
                                                                        v
                                                              [Matching engine]
                                                              (order book + logic)
                                                                        |
                                                                        v
                                                        trades + market data out

The user talks to a broker, which is the trading app. The broker sends orders to the exchange gateway Source 1সোর্স 1. The gateway checks the order and stamps it with a number that fixes its place in line Source 1সোর্স 1. Then the matching engine pairs buy and sell orders and reports the trades Source 1সোর্স 1. The article calls the whole design asynchronous and event-sourced Source 1সোর্স 1.

What event-sourced means

In an event-sourced system, the main record is a list of everything that happened, in order. The current state is what you get when you replay that list from the start. A bank statement works the same way: your balance is the sum of all the lines.

সহজ English

The user talks to a broker, which is the trading app. The broker sends orders to the gateway of the exchange Source 1সোর্স 1. The gateway checks each order and gives it a number. That number fixes the place of the order in the line Source 1সোর্স 1. Then the matching engine pairs buy orders with sell orders and reports the trades Source 1সোর্স 1. The article calls the whole design asynchronous and event-sourced Source 1সোর্স 1.

In the diagram, the user app talks to the broker with REST or WebSocket, and the broker talks to the gateway with FIX. The gateway connects to a risk manager, a wallet, and an order manager. The order manager adds a sequence number and sends the order to the matching engine, which holds the order book and the logic. Trades and market data come out of the engine.

In an event-sourced system, the main record is a list of all the events, in order. To get the current state, you replay that list from the start. A bank statement is similar: your balance is the sum of all the lines.

বাংলা ব্যাখ্যা

User একটি broker-এর সঙ্গে কথা বলেন; broker হলো trading app। Broker order-গুলো exchange-এর gateway-তে পাঠায় Source 1সোর্স 1। Gateway order-টি check করে এবং তাতে একটি নম্বর বসিয়ে দেয়, যা line-এ order-টির জায়গা ঠিক করে Source 1সোর্স 1। তারপর matching engine buy আর sell order জোড়া মেলায় এবং trade-গুলো জানায় Source 1সোর্স 1। Article-টি পুরো design-কে asynchronous এবং event-sourced বলে Source 1সোর্স 1।

Diagram-এ user app REST বা WebSocket দিয়ে broker-এর সঙ্গে কথা বলে, আর broker FIX দিয়ে gateway-এর সঙ্গে কথা বলে। Gateway একটি risk manager, একটি wallet এবং একটি order manager-এর সঙ্গে যুক্ত। Order manager একটি sequence number যোগ করে order-টি matching engine-এ পাঠায়; matching engine-এ order book আর logic থাকে। Engine থেকে trade আর market data বের হয়।

Event-sourced system-এ মূল record হলো যা যা ঘটেছে তার একটি ক্রমানুসারী তালিকা। শুরু থেকে এই তালিকা replay করলে বর্তমান state পাওয়া যায়। Bank statement-ও একইভাবে কাজ করে: আপনার balance হলো সব লাইনের যোগফল।

Orders and the order book

Think of two queues at a busy market stall. One queue holds buyers, sorted so the highest offer stands at the front. The other holds sellers, sorted so the lowest price stands at the front.

That pair of queues is the order book. For one stock, it shows every waiting buy and sell order, with its amount and its price Source 1সোর্স 1. Buy orders are sorted from the highest price down. Sell orders are sorted from the lowest price up Source 1সোর্স 1. A trade happens where the two sides meet Source 1সোর্স 1.

The article explains a few trading terms Source 1সোর্স 1:

TermPlain meaning
Market order"Buy or sell now at the current price." It fills at once if there are enough shares on the other side.
Limit order"Buy or sell only at my price or better." A buy limit of 100 can fill at 100 or less. A sell limit of 100 can fill at 100 or more.
SpreadThe gap from the best (highest) buy offer to the best (lowest) sell offer

সহজ English

Think of two lines at a busy market stall. One line holds buyers, with the highest offer at the front. The other line holds sellers, with the lowest price at the front.

These two lines are the order book. For one stock, it shows each waiting buy order and sell order, with its amount and its price Source 1সোর্স 1. Buy orders go from the highest price down. Sell orders go from the lowest price up Source 1সোর্স 1. A trade happens where the two sides meet Source 1সোর্স 1.

The article explains some trading terms Source 1সোর্স 1:

  • Market order. Buy or sell now at the current price. It fills immediately if the other side has enough shares.
  • Limit order. Buy or sell only at your price or better. A buy limit of 100 can fill at 100 or less. A sell limit of 100 can fill at 100 or more.
  • Spread. The gap between the best (highest) buy offer and the best (lowest) sell offer.

বাংলা ব্যাখ্যা

একটি ব্যস্ত বাজারের দোকানে দুটি সারির কথা ভাবুন। একটি সারিতে ক্রেতারা থাকেন, সবচেয়ে বেশি দাম দেওয়া ক্রেতা সামনে। অন্য সারিতে বিক্রেতারা থাকেন, সবচেয়ে কম দাম চাওয়া বিক্রেতা সামনে।

এই দুটি সারিই হলো order book। একটি stock-এর জন্য এটি প্রতিটি অপেক্ষমাণ buy ও sell order দেখায়, তার পরিমাণ ও দামসহ Source 1সোর্স 1। Buy order-গুলো সবচেয়ে বেশি দাম থেকে নিচের দিকে সাজানো থাকে। Sell order-গুলো সবচেয়ে কম দাম থেকে ওপরের দিকে সাজানো থাকে Source 1সোর্স 1। যেখানে দুই দিক মিলে যায়, সেখানে trade হয় Source 1সোর্স 1।

Article-টি কয়েকটি trading শব্দ ব্যাখ্যা করে Source 1সোর্স 1:

  • Market order। "এখনই বর্তমান দামে কিনুন বা বেচুন।" অন্য দিকে যথেষ্ট share থাকলে এটি সঙ্গে সঙ্গে fill হয়।
  • Limit order। "শুধু আমার দামে বা তার চেয়ে ভালো দামে কিনুন বা বেচুন।" 100-এর buy limit 100 বা তার কমে fill হতে পারে। 100-এর sell limit 100 বা তার বেশিতে fill হতে পারে।
  • Spread। সবচেয়ে ভালো (সর্বোচ্চ) buy offer আর সবচেয়ে ভালো (সর্বনিম্ন) sell offer-এর মধ্যে ফাঁক।

The broker and the FIX protocol

A broker is like a travel agent. You do not phone each airline. You ask the agent, and the agent talks to the airlines in their own language.

A user connects to the broker with REST APIs, and with WebSockets for live prices Source 1সোর্স 1. A WebSocket is a connection that stays open, so the server can push updates without being asked. The broker then talks to the exchange gateway in the Financial Information Exchange protocol, or FIX Source 1সোর্স 1.

FIX is a standard message format for trading. The article says FIX gives each order message a unique sequence number Source 1সোর্স 1. It also adds a checksum and the message length, so the receiver can see if a message got damaged on the way Source 1সোর্স 1. A checksum is a small number computed from the message. If the number does not match on arrival, the message is broken.

সহজ English

A broker is like a travel agent. You do not phone each airline. You ask the agent, and the agent talks to the airlines in their own language.

A user connects to the broker with REST APIs. For live prices, the user connects with WebSockets Source 1সোর্স 1. A WebSocket connection stays open, so the server can send updates without a request. The broker then talks to the gateway of the exchange in the Financial Information Exchange protocol (FIX) Source 1সোর্স 1.

FIX is a standard message format for trading. The article says that FIX gives each order message a unique sequence number Source 1সোর্স 1. FIX also adds a checksum and the message length, so the receiver can see if a message got damaged on the way Source 1সোর্স 1. A checksum is a small number that is calculated from the message. If the number is different on arrival, the message is broken.

বাংলা ব্যাখ্যা

Broker অনেকটা travel agent-এর মতো। আপনি প্রতিটি airline-কে ফোন করেন না। আপনি agent-কে বলেন, আর agent airline-গুলোর সঙ্গে তাদের নিজের ভাষায় কথা বলে।

User REST API দিয়ে broker-এর সঙ্গে যুক্ত হন, আর live দামের জন্য WebSocket ব্যবহার করেন Source 1সোর্স 1। WebSocket হলো এমন একটি connection যা খোলা থাকে, তাই server না চাইতেই update পাঠাতে পারে। তারপর broker exchange gateway-এর সঙ্গে Financial Information Exchange protocol, অর্থাৎ FIX-এ কথা বলে Source 1সোর্স 1।

FIX হলো trading-এর জন্য একটি standard message format। Article বলে, FIX প্রতিটি order message-কে একটি unique sequence number দেয় Source 1সোর্স 1। এটি একটি checksum আর message-এর length-ও যোগ করে, যাতে পথে কোনো message নষ্ট হলে receiver তা বুঝতে পারে Source 1সোর্স 1। Checksum হলো message থেকে হিসাব করা একটি ছোট সংখ্যা। পৌঁছানোর পর সংখ্যাটি না মিললে message-টি ভাঙা।

The gateway: checks before the line

Think of the security desk at an office. Before you get into the lift, a guard checks your badge and writes your name in the visitor book.

The gateway is the front door for brokers Source 1সোর্স 1. It turns each order into the exchange's internal format and later sends results back Source 1সোর্স 1. A gateway can also sit close to the exchange servers to cut delay. This is called co-location Source 1সোর্স 1.

The article splits the gateway into three parts Source 1সোর্স 1:

PartJob
Risk managerChecks that the user has enough funds, blocks odd trading, and works out fees
WalletHolds the user's money and shares for trading
Order managerGives each order a sequence number, tracks its state, and sends approved orders on

The order manager keeps a light list of every order: open, cancelled, and rejected Source 1সোর্স 1. It also handles cancel requests Source 1সোর্স 1.

সহজ English

Think of the security desk at an office. Before you go to the lift, a guard checks your badge and writes your name in the visitor book.

The gateway is the front door for brokers Source 1সোর্স 1. It changes each order into the internal format of the exchange, and later sends the results back Source 1সোর্স 1. A gateway can also be near the exchange servers to decrease the delay. This is co-location Source 1সোর্স 1.

The article divides the gateway into three parts Source 1সোর্স 1:

  • Risk manager. It checks that the user has sufficient funds, stops unusual trading, and calculates fees.
  • Wallet. It holds the money and shares of the user for trading.
  • Order manager. It gives each order a sequence number, tracks its state, and sends approved orders forward.

The order manager keeps a light list of all orders: open, cancelled, and rejected Source 1সোর্স 1. It also handles cancel requests Source 1সোর্স 1.

বাংলা ব্যাখ্যা

একটি অফিসের security desk-এর কথা ভাবুন। Lift-এ ওঠার আগে একজন guard আপনার badge দেখেন এবং visitor book-এ আপনার নাম লেখেন।

Gateway হলো broker-দের জন্য সামনের দরজা Source 1সোর্স 1। এটি প্রতিটি order-কে exchange-এর internal format-এ বদলে নেয় এবং পরে ফলাফল ফেরত পাঠায় Source 1সোর্স 1। Delay কমাতে একটি gateway exchange server-এর কাছাকাছিও থাকতে পারে। একে co-location বলে Source 1সোর্স 1।

Article-টি gateway-কে তিনটি অংশে ভাগ করে Source 1সোর্স 1:

  • Risk manager। User-এর যথেষ্ট fund আছে কি না check করে, অস্বাভাবিক trading আটকায়, এবং fee হিসাব করে।
  • Wallet। Trading-এর জন্য user-এর টাকা ও share রাখে।
  • Order manager। প্রতিটি order-কে একটি sequence number দেয়, তার state track করে, এবং approved order-গুলো সামনে পাঠায়।

Order manager প্রতিটি order-এর একটি হালকা তালিকা রাখে: open, cancelled এবং rejected Source 1সোর্স 1। এটি cancel request-ও সামলায় Source 1সোর্স 1।

Sequence numbers: a ticket for every order

At a bakery, you pull a paper ticket when you walk in. The baker serves ticket 41 before ticket 42, no matter who shouts louder. Nobody can argue about who came first.

The order manager does the same. It gives every order, cancel, and fill a number that always goes up across the whole exchange Source 1সোর্স 1. A fill is a completed trade, in full or in part. The article lists what these numbers give Source 1সোর্স 1:

  • Fair order. Orders are handled in the order they arrived.
  • Fast recovery. After a crash, the system can replay events in the same order and reach the same state.
  • Exactly once. Each event takes effect one time, not zero times and not twice.
  • Gap detection. A missing number shows at once that an event got lost Source 1সোর্স 1.

The article adds one more idea. Each message type (new order, cancel, trade) gets its own topic queue with its own numbers Source 1সোর্স 1. A topic queue is a named line of messages that a program reads in order. Separate lines keep each stream in order, let each type move at its own pace, and make replay simpler Source 1সোর্স 1.

সহজ English

At a bakery, you take a ticket when you come in. The baker serves ticket 41 before ticket 42, even if another person shouts louder.

The order manager gives each order, cancel, and fill a number that always goes up across the whole exchange Source 1সোর্স 1. A fill is a completed trade, full or partial. These numbers give Source 1সোর্স 1:

  • Fair order. The system handles orders in the order that they arrived.
  • Fast recovery. After a crash, the system can replay the events in the same order and get the same state.
  • Exactly once. Each event has an effect one time. Not zero times, and not two times.
  • Gap detection. A missing number shows immediately that an event is lost Source 1সোর্স 1.

Each message type (new order, cancel, trade) also gets its own topic queue with its own numbers Source 1সোর্স 1. A topic queue is a named line of messages that a program reads in order. Separate lines keep each stream in order, let each type move at its own speed, and make replay simpler Source 1সোর্স 1.

বাংলা ব্যাখ্যা

একটি bakery-তে ঢোকার সময় আপনি একটি কাগজের ticket নেন। কে বেশি জোরে চিৎকার করছে তা যাই হোক, baker 42 নম্বরের আগে 41 নম্বর ticket-কে ডাকেন। কে আগে এসেছে, তা নিয়ে কেউ তর্ক করতে পারে না।

Order manager-ও তাই করে। এটি প্রতিটি order, cancel এবং fill-কে এমন একটি নম্বর দেয় যা পুরো exchange জুড়ে সবসময় বাড়ে Source 1সোর্স 1। Fill হলো একটি সম্পূর্ণ হওয়া trade, পুরোপুরি বা আংশিক। Article অনুযায়ী এই নম্বরগুলো যা দেয় Source 1সোর্স 1:

  • ন্যায্য ক্রম। Order-গুলো যে ক্রমে এসেছে, সেই ক্রমেই handle হয়।
  • দ্রুত recovery। Crash-এর পর system একই ক্রমে event-গুলো replay করে একই state-এ পৌঁছাতে পারে।
  • Exactly once। প্রতিটি event ঠিক একবার কাজ করে, শূন্যবার নয়, দুবারও নয়।
  • Gap detection। একটি নম্বর হারিয়ে গেলে সঙ্গে সঙ্গে বোঝা যায় যে একটি event হারিয়েছে Source 1সোর্স 1।

প্রতিটি message type (new order, cancel, trade) নিজের নম্বরসহ নিজস্ব topic queue-ও পায় Source 1সোর্স 1। Topic queue হলো message-এর একটি নাম দেওয়া সারি, যা একটি program ক্রম অনুযায়ী পড়ে। আলাদা সারি প্রতিটি stream-কে ক্রমে রাখে, প্রতিটি type-কে নিজের গতিতে চলতে দেয়, এবং replay সহজ করে Source 1সোর্স 1।

The matching engine

The matching engine is the heart of the exchange. It checks the sequence numbers, pairs buy and sell orders, and turns trades into market data Source 1সোর্স 1.

The order book in memory. The engine keeps the order book in memory, not on disk, for each stock Source 1সোর্স 1. Each stock has one list for buys and one for sells Source 1সোর্স 1. Inside each price level, orders wait in arrival order, first in and first out Source 1সোর্স 1. The article uses a doubly linked list for each price level. A doubly linked list is a chain where each item knows its neighbour on both sides. Adding to the end takes constant time, and so does removing a known item Source 1সোর্স 1.

Fast cancels. Searching every price level for one order would be slow. So the engine keeps an index from order ID to the order in memory, which makes a cancel a single lookup Source 1সোর্স 1. This matters because cancels are about 40% of all messages.

The matching rule. The engine makes a trade when the buy price is equal to or higher than the sell price Source 1সোর্স 1. The engine also tracks the best buy and best sell prices so it can match quickly Source 1সোর্স 1. A closed order leaves the book and goes into the trade history Source 1সোর্স 1.

Why the engine must be deterministic

The article says the same input sequence must always produce the same output sequence Source 1সোর্স 1. "Deterministic" means no luck and no timing effects. If a replay after a crash gave different trades, the exchange could not prove what really happened.

The free part of the article stops after the matching logic. This page covers only that free part.

সহজ English

The matching engine is the heart of the exchange. It checks the sequence numbers, pairs buy and sell orders, and changes trades into market data Source 1সোর্স 1.

The engine keeps the order book of each stock in memory, not on disk Source 1সোর্স 1. Each stock has one list for buys and one for sells Source 1সোর্স 1. At each price level, orders wait in arrival order: first in, first out Source 1সোর্স 1. The article uses a doubly linked list for each price level. Each item in this chain knows its neighbours on both sides. Adding to the end and removing a known item take constant time Source 1সোর্স 1.

For fast cancels, the engine keeps an index from order ID to the order in memory. Thus a cancel is one lookup Source 1সোর্স 1.

The engine makes a trade when the buy price is equal to or higher than the sell price Source 1সোর্স 1. It tracks the best buy and sell prices to match quickly Source 1সোর্স 1. A closed order goes from the book into the trade history Source 1সোর্স 1.

The same input sequence must always give the same output sequence Source 1সোর্স 1.

বাংলা ব্যাখ্যা

Matching engine হলো exchange-এর হৃদয়। এটি sequence number check করে, buy ও sell order জোড়া মেলায়, এবং trade-গুলোকে market data-তে পরিণত করে Source 1সোর্স 1।

Engine প্রতিটি stock-এর order book disk-এ নয়, memory-তে রাখে Source 1সোর্স 1। প্রতিটি stock-এর buy-এর জন্য একটি আর sell-এর জন্য একটি তালিকা থাকে Source 1সোর্স 1। প্রতিটি price level-এ order-গুলো আসার ক্রমে অপেক্ষা করে, first in, first out Source 1সোর্স 1। Article প্রতিটি price level-এর জন্য একটি doubly linked list ব্যবহার করে। এটি এমন একটি chain যেখানে প্রতিটি item দুই পাশের প্রতিবেশীকে চেনে। শেষে যোগ করতে constant time লাগে, আর একটি জানা item সরাতেও constant time লাগে Source 1সোর্স 1।

একটি order-এর জন্য সব price level খোঁজা ধীর হতো। তাই engine order ID থেকে memory-তে থাকা order-এর একটি index রাখে, ফলে একটি cancel মাত্র একটি lookup Source 1সোর্স 1। এটি গুরুত্বপূর্ণ, কারণ সব message-এর প্রায় 40% cancel।

Buy price যখন sell price-এর সমান বা বেশি, তখন engine একটি trade করে Source 1সোর্স 1। দ্রুত match করতে engine সবচেয়ে ভালো buy ও sell price track করে Source 1সোর্স 1। একটি closed order, book থেকে সরে trade history-তে যায় Source 1সোর্স 1।

Article বলে, একই input sequence থেকে সবসময় একই output sequence আসতে হবে Source 1সোর্স 1। Crash-এর পর replay ভিন্ন trade দিলে exchange প্রমাণ করতে পারত না আসলে কী ঘটেছিল। এই page শুধু article-এর free অংশ, অর্থাৎ matching logic পর্যন্ত, নিয়ে কথা বলে।

Key words

WordPlain meaning
OrderA request to buy or sell a number of shares, maybe at a set price
Order bookThe two sorted lists of waiting buy and sell orders for one stock
Matching engineThe program that pairs buy and sell orders into trades
BrokerThe app or firm that sends your orders to the exchange
GatewayThe front door that checks orders before they reach the engine
Sequence numberA number that always goes up and fixes the order of events
QueueA line of messages read in order
Market dataThe live stream of prices and trades that the exchange publishes
Event sourcingStoring every change as an event, so you can replay history
LatencyThe delay between sending a message and getting the result

What a tester can learn

Tutorial advice

These test ideas are the tutorial's own advice, not claims from the article.

  • Price and time priority. Place two buy orders at the same price a moment apart. Check that the earlier one fills first.
  • Replay gives the same result. Feed a recorded order stream into the engine twice. Check that the two trade outputs are byte for byte the same.
  • Cancel races. Send a cancel at the same moment as a matching order. Check that the order either fills or cancels, never both.
  • Gaps and duplicates. Drop or repeat one sequence number on purpose. Check that the system detects the gap and does not apply a trade twice.
  • Limits and funds. Try to trade more than the daily limit, or more than the wallet holds. Check that the risk manager rejects the order.
  • Cancel storms. Load test with about 40% cancels, not only new orders, to match the real message mix.

সহজ English

These test ideas are the tutorial's own advice. They are not claims from the article.

  • Price and time priority. Put two buy orders at the same price, a short time apart. Make sure that the earlier one fills first.
  • Replay gives the same result. Send a recorded order stream into the engine two times. Make sure that the two trade outputs are the same, byte for byte.
  • Cancel races. Send a cancel at the same time as a matching order. Make sure that the order fills or cancels, but never both.
  • Gaps and duplicates. Remove or repeat one sequence number on purpose. Make sure that the system finds the gap and does not apply a trade two times.
  • Limits and funds. Try to trade more than the daily limit, or more than the wallet holds. Make sure that the risk manager rejects the order.
  • Cancel storms. In a load test, use about 40% cancels, not only new orders, to match the real message mix.

বাংলা ব্যাখ্যা

নিচের test ধারণাগুলো এই tutorial-এর নিজস্ব পরামর্শ, article-এর দাবি নয়।

  • Price ও time priority। একই দামে অল্প সময়ের ব্যবধানে দুটি buy order দিন। দেখুন, আগের order-টি আগে fill হয় কি না।
  • Replay-তে একই ফল। একটি recorded order stream দুবার engine-এ দিন। দেখুন, দুটি trade output byte ধরে হুবহু এক কি না।
  • Cancel race। একটি matching order-এর ঠিক একই মুহূর্তে একটি cancel পাঠান। দেখুন, order-টি হয় fill হয়, নয়তো cancel হয়, কখনো দুটোই নয়।
  • Gap ও duplicate। ইচ্ছা করে একটি sequence number বাদ দিন বা দুবার পাঠান। দেখুন, system gap ধরতে পারে কি না এবং কোনো trade দুবার apply করে না কি না।
  • Limit ও fund। Daily limit-এর বেশি, বা wallet-এ যা আছে তার বেশি trade করার চেষ্টা করুন। দেখুন, risk manager order-টি reject করে কি না।
  • Cancel storm। আসল message mix-এর সঙ্গে মেলাতে load test-এ শুধু নতুন order নয়, প্রায় 40% cancel রাখুন।

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

  1. [1]
    How Stock Exchange Works

    The System Design Newsletter (Neo Kim) · accessed 2026-10-20দেখা হয়েছে: 2026-10-20