Skip to main content

System Overview

Tracera is a multi-layered system designed for real-time financial data processing. The architecture separates concerns across ingestion, computation, storage, and delivery layers.

Architecture Diagram

┌──────────────────────────────────────────────────────────────────────┐
│                        CLIENTS (Web / CLI)                          │
│                    WebSocket + REST connections                      │
└──────────────────────┬───────────────────────────────────────────────┘


┌──────────────────────────────────────────────────────────────────────┐
│                         API LAYER (Gin)                              │
│                                                                      │
│  REST Endpoints              WebSocket Hub                           │
│  ─────────────               ─────────────                           │
│  GET  /api/v1/items          GET /api/v1/ws  (price + volatility)    │
│  GET  /api/v1/items/:id                                              │
│  GET  /api/v1/items/:id/history                                      │
│  GET  /api/v1/items/:id/volatility                                   │
│  GET  /api/v1/rankings/volatile                                      │
│  GET  /api/v1/portfolio      (current portfolio valuation)           │
│  POST /api/v1/portfolio/import (Steam inventory sync)                │
└──────────────────────┬───────────────────┬───────────────────────────┘
                       │                   │
           ┌───────────┘                   └───────────┐
           ▼                                           ▼
┌─────────────────────────┐           ┌──────────────────────────┐
│   VOLATILITY ENGINE     │           │    PRICE INGESTION       │
│                         │           │                          │
│  • Rolling std dev      │           │  • Polls Steam Market    │
│  • Bollinger bands      │           │  • Polls 3rd-party APIs  │
│  • % change tracking    │           │  • Normalizes prices     │
│  • Trend detection      │           │  • Deduplicates data     │
│  • Sharpe-like ratios   │           │  • Writes to TimescaleDB │
│                         │           │  • Publishes to Redis    │
└────────────┬────────────┘           └─────────────┬────────────┘
             │                                      │
             ▼                                      ▼
┌──────────────────────────────────────────────────────────────────────┐
│                        DATA LAYER                                    │
│                                                                      │
│  ┌─────────────────────────┐    ┌──────────────────────────────┐    │
│  │      TimescaleDB        │    │           Redis               │    │
│  │                         │    │                               │    │
│  │  • price_history        │    │  • Current prices (cache)     │    │
│  │    (hypertable)         │    │  • Pub/Sub channels           │    │
│  │  • items (metadata)     │    │  • Volatility rankings        │    │
│  │  • continuous aggs      │    │    (sorted sets)              │    │
│  │    (1h, 24h, 7d)       │    │  • Rate limit counters        │    │
│  │  • user_portfolio_*     │    │  • Portfolio import cooldown  │    │
│  └─────────────────────────┘    └──────────────────────────────┘    │
│                                                                      │
└──────────────────────────────────────────────────────────────────────┘

Layer Responsibilities

API Layer (Gin)

The HTTP layer handles routing, middleware, and request/response serialization. Built on the Gin framework for minimal overhead and high throughput.
  • REST endpoints for items, prices, volatility metrics, and portfolio management
  • WebSocket hub for broadcasting live price and volatility updates
  • Middleware stack including authentication, CSRF protection, rate limiting, and security headers

Price Ingestion

A scheduled background process that fetches prices from multiple market sources:
  • Steam Market API — Official base price data and listing counts
  • PriceEmpire API — Aggregated prices from additional marketplaces
  • Provider interface — Extensible design for adding new sources (CSFloat, Skinport planned)
Ingestion runs concurrently using goroutine fan-out, isolating provider failures per cycle.

Volatility Engine

Computes financial metrics from pre-aggregated TimescaleDB data:
  • Rolling standard deviation, Bollinger bands, percentage change
  • Trend detection via linear regression
  • Coefficient of variation for cross-price-range comparison
Results are cached in Redis and pushed to connected WebSocket clients.

Data Layer

Dual-database architecture optimized for different access patterns:
  • TimescaleDB — Durable storage for historical price data, continuous aggregates, and user data
  • Redis — Hot cache for latest prices, pub/sub for real-time broadcasting, session storage, and rate limiting

Request Flow

A typical price update flows through the system like this:
1

Ingestion

The scheduler triggers a price fetch cycle. Providers are queried concurrently.
2

Storage

Raw prices are batch-inserted into TimescaleDB via COPY protocol. Latest prices are cached in Redis.
3

Computation

The volatility engine reads pre-aggregated data from continuous aggregates and computes metrics.
4

Publishing

Updated prices and volatility metrics are published to Redis Pub/Sub channels.
5

Delivery

The WebSocket hub receives published updates and broadcasts them to subscribed clients.