# kxsystems/kdb-tick architecture

> Architecture diagram of the GitHub repository kxsystems/kdb-tick, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kxsystems/kdb-tick
- Repository: https://github.com/kxsystems/kdb-tick

## Overview

##### Project type and purpose
- tick.q – the “vanilla” tickerplant (TP) for ingesting and timestamping live data
- tick/r.q – the RDB (historical store) that subscribes to the TP and persists snapshots
- tick/u.q – the pub/sub script that client applications use to receive live updates
- Purpose: streamline market‑data acquisition (tickerplant), realtime dissemination (pub/sub), and storage (RDB).

##### File structure
- Top‐level:
- tick.q (script that launches the TP on port X)
- tick/ directory with:
– r.q (launches the RDB, usually on port Y)
– u.q (client subscription logic)
- No frontend/backend folders—this is a streaming‑data pipeline with distinct processes.
- The presence of only q scripts and no build/deploy configs indicates manual or kdb+ startup orchestration via shell scripts or system services.

##### README for additional insights
- Describes exactly how tick.q, r.q, and u.q interact and references kdb+ documentation.

a. Main Components
- Market Data Feed (external exchange or synthetic feed)
- Tickerplant process (tick.q)
- RDB process (tick/r.q)
- Subscriber processes (tick/u.q or other client apps)
- Underlying kdb+ instances (in‐memory tables, logs on disk)
b. Relationships and Interactions
- Market Data Feed pushes messages into the Tickerplant via TCP.
- The Tickerplant timestamps & logs every message to a local “log” file, then republishes it.
- RDB subscribes to the TP feed, writes rolling snapshots to disk (historical table), and optionally serves queries.
- Subscriber clients connect to the TP (and optionally to the RDB) to receive live tick updates.
c. Architectural Patterns
- Pub/Sub for real‐time distribution
- Write‐ahead logging in TP for recovery
- Snapshotting in RDB for persistence
- Separation of concerns: ingestion vs. persistence vs. consumption
d. Key Technologies
- kdb+ / q language
- TCP IPC between q processes
- File‐based logging (TP log files)
- Snapshot files on disk (RDB)

##### Elements
- Labels: “Market Data Feed,” “TP (tick.q),” “RDB (r.q),” “Subscriber (u.q).”
– Feed → TP → (RDB & Subscribers)
– RDB → Disk (snapshots)
– TP → Disk (log files)
– Ingestion (blue), Persistence (green), Consumption (orange)
– Rectangles for processes
- Annotations for ports and file paths, e.g., TP log file location, snapshot directory.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Documentation
    DOC["Project Documentation (README.md)"]:::external

    %% Ingestion Layer
    subgraph "Ingestion Layer"
        MDF["Market Data Feed"]:::external
        TP["Tickerplant (tick.q)"]:::ingestion
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        RDB["RDB (tick/r.q)"]:::persistence
    end

    %% Storage
    subgraph "Storage"
        Log["TP Log File"]:::storage
        Snap["Snapshot Directory"]:::storage
    end

    %% Consumption Layer
    subgraph "Consumption Layer"
        SUB["Subscriber (tick/u.q)"]:::consumption
    end

    %% Connections
    DOC --> MDF
    MDF -->|"TCP :5000"| TP
    TP -->|"write-ahead logging"| Log
    TP -->|"publish ticks (TCP)"| RDB
    TP -->|"publish ticks (TCP)"| SUB
    RDB -->|"write snapshots"| Snap
    RDB -->|"replay log on startup"| Log

    %% Click Events
    click TP "https://github.com/kxsystems/kdb-tick/blob/master/tick.q"
    click RDB "https://github.com/kxsystems/kdb-tick/blob/master/tick/r.q"
    click SUB "https://github.com/kxsystems/kdb-tick/blob/master/tick/u.q"
    click DOC "https://github.com/kxsystems/kdb-tick/blob/master/README.md"

    %% Styles
    classDef ingestion fill:#D0E6FF,stroke:#0000FF,color:#000;
    classDef persistence fill:#DFFFE0,stroke:#00AA00,color:#000;
    classDef consumption fill:#FFEFD0,stroke:#FFAA00,color:#000;
    classDef storage fill:#F0F0F0,stroke:#AAAAAA,color:#000,stroke-dasharray:5 5;
    classDef external fill:#FFFFFF,stroke:#888888,color:#000,stroke-dasharray:2 2;
```
