Welcome back to the second part of this series on building a kdb+ tick architecture. In the first part, we covered the core concepts and walked through each component — from the tickerplant and RDB/HDB/RTS to the gateway and beyond.
Now it’s time to put theory into practice: in this part, we’ll set up and run a full kdb+ tick architecture from scratch.
Setting Up the kdb+/q Environment
Before we can launch our tick architecture, we need to get kdb+ and q installed and configured on our machine. Head over to kx.com/kdb-personal-edition-download to download the free personal edition.
Alternatively, you can use the free sandbox (JupyterLab) provided on the KX Academy — no prerequisites needed, everything runs in the browser.
Once downloaded and unzipped (e.g., to C:\q), you must configure your environment variables:
Set QHOME:
setx QHOME "C:\q"
Add to PATH:
setx PATH "%PATH%;C:\q\w64"
Cloning the KxSystems git Repository
Clone the following repository to get the sample architecture scripts:
git clone https://github.com/KxSystems/kdb-architecture-course.git
Starting the Tickerplant (TP)
The tickerplant is the heart of the architecture. Launch it using:
q tick.q sym . -p 5010
The sym.q file defines our trade table:
trade:([]time:`timespan$();sym:`g#`symbol$();price:`float$();side:`symbol$())
Starting the Real-Time Database (RDB)
The RDB subscribes to the tickerplant and holds intraday data in memory. Launch it with:
q tick/rdb.q -p 5011
Starting the Feed Handler
The feed handler generates and sends data to the tickerplant. Launch it with:
q tick/feed.q
It opens a connection and generates random trades every second:
h_tp:hopen 5010;system"t 1000";
Starting the Historical Database (HDB)
The HDB serves data from disk. Launch it with:
q tick/hdb.q sym -p 5012
To simulate an End-of-Day (EOD) event, run this on the tickerplant:
q).u.endofday[]
Starting the Real-Time Subscriber (RTS)
The RTS performs custom logic on incoming data. Launch it with:
q tick/rts.q -p 5013
It maintains the latest price per symbol:
latestSymPrice: `sym xkey 0#trade;`latestSymPrice upsert select by sym from d
Starting the Gateway
The gateway is the single entry point for queries. Launch it with:
q tick/gw.q -p 5014
It routes queries to both HDB and RDB:
h_hdb:hopen 5012; h_rdb:hopen 5011;hdb,rdb
From Theory to Practice with kdb+
Building a fully operational tick architecture is a significant milestone in mastering kdb+. By wiring together the Tickerplant, RDB, HDB, and Gateway, you now have a system capable of handling the entire lifecycle of high-frequency data.
Ready to scale your architecture or integrate it with your enterprise Java environment? Our experts at MARGO are here to help you navigate the complexities of real-time data engineering.
Contact our expertsWhat is QHOME and why is it mandatory for the setup?
QHOME is an environment variable that tells the kdb+ system where to find its core files and libraries. Without it, the q interpreter cannot load essential functions or scripts necessary for the tick architecture to run.
How do I verify if a subscriber is correctly connected to the Tickerplant?
You can run the command .u.w in the Tickerplant process. It will return a dictionary listing all active subscribers and the specific tables they are monitoring, such as the RDB or RTS.
What happens to the data in the RDB during an End-of-Day (EOD) event?
During EOD, the Tickerplant notifies the RDB to save all its in-memory data to the disk as a new date partition. Once the save is complete, the RDB clears its local tables to start fresh for the next day.
Why does kdb+ use symbol enumeration in the HDB?
Symbol enumeration maps string-like symbols to integers in a sym file. This optimization significantly reduces memory usage and speeds up queries on large historical datasets by avoiding redundant string storage.
Can the Gateway handle queries for both today and yesterday at once?
Yes. The Gateway is designed to route a single query to both the RDB (real-time data) and the HDB (historical data), merging the results into one seamless response for the end user.