Back to IPC Overview

Interprocess Communication (IPC) · IPC Overview · Practice Question

How Are Ports Typically Configured in a kdb+ Tick Setup?

Sign in to track your progress

Question

How are ports typically configured across the processes in a kdb+ tick system? How does each process know what port to listen on and where to find the other processes?

Solution

The KX tick example ("kdb+tick") uses these ports by default:

Tickerplant:  5010
RDB:          5011
HDB:          5012

Each process is started with its own port via the -p flag:

q tick.q sym /data/tplogs -p 5010                     # tickerplant: schema file sym.q, logs in /data/tplogs
q tick/r.q localhost:5010 localhost:5012 -p 5011      # RDB: connects to the TP and the HDB
q /data/hdb -p 5012                                   # HDB: loads the database directory

Inside a script such as r.q, the addresses of the other processes are read from .z.x, the list of command-line arguments (as strings):

tpAddr: .z.x 0                        / "localhost:5010"
hdbAddr: .z.x 1                       / "localhost:5012"
tp: hopen `$":", tpAddr               / open a handle to the tickerplant

Explanation

kdb+ has no built-in port registry or service discovery. Port assignments are managed by convention and passed between processes via command-line arguments.

The -p flag sets the port a q process listens on:

q script.q -p 5010    # listen on port 5010

.z.x is the list of command-line arguments. Each process reads the addresses of other processes it needs from this list at startup. The order of arguments is a convention defined by the startup scripts:

# RDB startup: arg[0]=tickerplant, arg[1]=HDB
q tick/r.q localhost:5010 localhost:5012 -p 5011

Port conventions vary by organisation. The KX tick example uses 5010–5012 for the tickerplant, RDB and HDB; other processes (gateways, chained tickerplants, writers) are given ports by each organisation. Common variations:

  • Add a digit prefix for environment: 15010 for prod, 25010 for UAT, 35010 for dev
  • Add an asset class suffix: 5010 for equities, 5020 for FX, 5030 for futures
  • Use a multiplier scheme: 50100 for tickerplant of system 10

Process registries are used in larger systems instead of hardcoded port arguments. A dedicated q process maps process names to addresses, and each starting process asks it where to connect. For example, if the registry defines a function getAddr that returns an address such as `:host1:5010:

registry: hopen `:reghost:5000        / connect to the registry
tp: hopen registry (`getAddr; `tp)   / ask it for the tickerplant's address, then connect

This allows processes to be restarted on different ports without changing all their dependents' startup scripts — only the registry needs to be updated.

Within a single machine, processes connect using localhost or :: (the loopback address). Across machines, the full hostname or IP address is used.