시스템 디자인 아틀라스
금융 시스템 / 시장 구조 / Stock Exchange
학습 로드맵

주식 거래소 설계

주문은 빠르게 받되, 체결 순서는 공정하고 재생 가능해야 합니다. risk check, symbol sequencing, price-time order book, market-data fan-out을 분리해 한 체결의 원인과 순서를 끝까지 설명합니다.

개념 이해요구사항장애 대응진도 저장
30초 핵심 요약

한 symbol의 matching engine은 fenced epoch 안에서 단일 sequenced writer로 동작합니다. order가 durable sequence를 받은 뒤에만 매칭하며, execution·book delta·risk reservation update를 같은 engine event에서 만듭니다. market data는 빠른 fan-out과 gap recovery를, standby는 snapshot+log replay와 book hash 검증을 책임집니다.

ORDERINGsymbol → epoch → engine seq
PRIORITYbest price → FIFO
RECOVERYsnapshot + deterministic replay
01 · REQUIREMENTS

빠른 수신과 거래 상태의 정본을 분리한다

# 요구사항

gateway receipt는 네트워크 수신 증거이고, engine report는 order book 상태 증거입니다. 두 ACK를 같은 성공으로 표현하면 timeout·retry·failover에서 중복 체결과 감사 공백이 생깁니다.

F1Pre-trade controls

session·limit·price collar·rate·STP를 command 전 검사·reserve합니다.

F2Deterministic order

symbol shard의 engine sequence가 price-time priority의 입력 경계입니다.

F3Atomic lifecycle

partial fill, cancel, replace, reservation과 execution을 sequenced event로 남깁니다.

F4Recoverable feed

market data drop은 feed gap과 snapshot/replay로 수렴시킵니다.

02 · HIGH-LEVEL DESIGN

risk, sequence, match, delivery의 책임 경계

# 아키텍처
order command → risk reserve → symbol sequence → match → reports / feed SVG DIAGRAM · engine의 single writer는 설계 선택
주식 거래소의 order gateway, risk check, sequencer, matching engine, market data와 recovery 구조participant 주문이 gateway와 risk control을 지나 symbol sequencer에 들어가 matching engine에서 체결된다. 체결은 private report와 market-data fan-out으로 전달되고 durable log와 standby replay가 복구를 담당한다.OMS / Participantclient order IDsequence + signatureGateway + risklimits · collars · STPreserve / rejectSymbol sequencerepoch + engine seqdurable appendMatching engineprice → timeorders + tradesDurable event logcommand · execution · auditsnapshot + replayPrivate reportsexecution · cancelparticipant replayMarket datafeed seq · gapsnapshot recoveryone active fenced writer per symbol shard
공정성 경계: client send time이나 network arrival만으로 priority를 정하지 않습니다. venue가 정의한 risk acceptance·sequencing boundary에서 engine sequence를 붙이고, 같은 price에서는 그 sequence 순서로 FIFO를 유지합니다.
03 · MATCH FLOW

order의 실제 상태는 engine sequence 뒤에 결정된다

# 요청 흐름
01Validate

identity, payload hash, rate, collar, risk reservation을 확인합니다.

02Sequence

symbol ownership epoch와 durable engine sequence를 부여합니다.

03Match

best opposite price의 FIFO queue를 소비하며 partial execution을 만듭니다.

04Publish

private report·risk update·book delta를 fan-out하고 gap을 복구합니다.

04 · TRADEOFFS

단일 writer의 지연 비용과 결정적 복구의 이점

# 트레이드오프
선택
강점
제약
설계 기준
symbol single writer
fair order
hot symbol vertical limit
continuous price-time book의 기본
multi-writer levels
throughput
cross-price race·replay 복잡
독립 auction semantics가 명확할 때
log-before-apply
replay
append latency
regulated execution evidence
direct feed multicast
low latency
drop/reorder 가능
feed seq + snapshot recovery 필수
05 · FAILURE MODES

sequence·risk·feed·control의 실패를 따로 복구한다

# 장애 시나리오
client retry

timeout 뒤 같은 주문이 다시 들어와 두 번 resting 또는 fill될 수 있습니다.

대응 · participant-scoped client ID + payload hash로 logical order 하나를 대사합니다.
!risk stale/timeout

limit 정보가 늦거나 risk dependency가 멈춰 과도한 order가 통과할 위험입니다.

대응 · versioned reservation과 fail-closed/controlled halt policy를 audit합니다.
append failure

accepted ACK가 났지만 durable sequence에 없는 command가 생길 수 있습니다.

대응 · durable append 전 engine accepted ACK 금지, receipt↔seq 대사를 둡니다.
split brain

active와 standby가 같은 symbol에서 다른 order book을 체결합니다.

대응 · epoch fencing·single NIC route·promotion drill·book hash 비교를 강제합니다.
hot symbol burst

opening/cancel burst가 queue와 engine p99를 올려 priority 지연을 만듭니다.

대응 · isolated shard·admission·slow feed consumer 분리를 적용합니다.
feed gap

subscriber가 packet drop/reorder 뒤 잘못된 best bid/ask를 볼 수 있습니다.

대응 · feed sequence gap replay 또는 snapshot+watermark로 book을 수렴시킵니다.
×cancel-match race

cancel 요청과 match가 경합해 고객 기대와 terminal event가 달라집니다.

대응 · engine sequence만 결과 정본으로 삼고 reservation/execution을 대사합니다.
unsafe halt control

operator control 오류로 market가 부당하게 열리거나 닫힐 수 있습니다.

대응 · dual control·signed sequenced halt/resume·replay checklist를 둡니다.
06 · OPERATIONS

통제·관측·비용을 market sequence에 연결한다

# 운영 관점
Market abuse controls

STP, rate/collar, order-to-cancel ratio, layering·spoofing signal을 rule version과 case audit에 묶습니다.

rule_version · order_lineage
Sequence observability

gateway receipt, risk, append→apply, engine p99, book invariant, feed gap, standby hash를 분리합니다.

engine_seq_gap · book_hash
Capacity cost

hot symbol core/NIC, durable log/snapshot, market-data egress, surveillance, hot standby와 drill을 합산합니다.

peak_skew × recovery_headroom
면접 모드 · 추가 질문06:00
“hot symbol cancel burst 중 active process가 NIC disconnect 되었습니다. standby promotion 전에 어떤 sequence·log durability·fence·book hash·market-data snapshot을 확인해야 두 order book이 다른 체결을 만들지 않는다고 설명하시겠습니까?”
fenced epochdurable sequenceprice-time FIFOsnapshot + replay
CONNECTED TOPIC결제 시스템에서 금전 효과와 조정 경계 보기
EDITORIAL NOTES

작성·검토·참고 자료

콘텐츠 원칙
이 문서는 독립적으로 재작성한 한국어 학습 자료입니다. 사실과 학습용 설계 가정을 구분합니다.
최종 검토
예상 학습 시간
28분

참고 자료

사실 오류·출처 정정은 문의·정정 페이지로 알려 주세요.