Skip to content

Architecture

The Virtufin examples project demonstrates a real-time market data pipeline.

System Overview

flowchart LR
    subgraph External
        BINANCE[Binance]
        ALPACA[Alpaca]
    end

    subgraph Virtufin
        WSM[WebSocketManager]
        WM[WorkManager]
        API[API Gateway]
    end

    subgraph Storage
        REDIS[(Redis/Valkey<br/>State Store)]
        PUBSUB[(Dapr Pub/Sub)]
    end

    BINANCE -->|wss://| WSM
    ALPACA -->|wss:// + auth| WSM
    WSM -->|Publish depth| PUBSUB
    WSM -->|Store snapshot| API
    API --> REDIS
    WM -->|Poll state| API
    WM -->|Publish imbalance| PUBSUB

Services Used

Service Role
WebSocketManager Manages external WebSocket connections, publishes messages to Dapr pub/sub
WorkManager Runs custom processing workers that react to pub/sub messages or state changes
API Gateway Provides REST API for state store CRUD operations

Data Flow

  1. Ingestion: WebSocketManager connects to Binance/Alpaca
  2. Persistence: Order book snapshots stored via API Gateway → state store
  3. Processing: WorkManager worker polls state store for new data, calculates metrics
  4. Output: Calculated imbalance published to pub/sub for downstream consumers