이벤트 소싱을 사용하여 폴리마켓 거래 시스템의 상태 드리프트

작성자

카테고리:

← 피드로
DEV Community · Trader Developer · 2026-06-18 개발(SW)

1kto1m

When building a real-time trading system for Polymarket, I assumed strategy and execution would be the hardest parts.

I was wrong.

The real issue was state drift – the system slowly stopped matching reality.

  1. What state drift looked like
  2. Incorrect positions
  3. Duplicate exposure
  4. Mismatch between bot state and real market state

There was no crash, only silent inconsistency.

  1. Why it happens
  2. WebSocket missing updates
  3. Delayed API responses
  4. Partial order fills
  5. Duplicate events
  6. Missing events
  7. In-memory state assumptions

  8. Core problem
    The system trusted runtime memory instead of reality.

  9. Solution: Event Sourcing

Store events instead of state:

  • trade events
  • order events
  • fill events

State is always rebuilt from history.

  1. Architecture

Event Log → State Rebuild → Current State

This makes the system deterministic and replayable.

  1. Reconciliation layer

Periodically:

  • fetch real positions
  • compare with internal state
  • correct drift
  1. Result
  2. No silent inconsistencies
  3. Easier debugging
  4. System can rebuild from scratch
  5. Reliable state tracking

  6. Key lesson
    State in trading systems is not stored – it is reconstructed.

원문에서 계속 ↗

코멘트

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다