Est. 2003 Advanced

Q

A terse, array-oriented programming language from Kx Systems that serves as the native query and analytics language for the kdb+ time-series database.

Created by Arthur Whitney

Paradigm Array, Functional
Typing Dynamic, strong
First Appeared 2003
Latest Version 4.1 (February 2024)

Q is a terse, array-oriented programming language developed by Arthur Whitney and released by Kx Systems in 2003. It is the native programming and query language of kdb+, a high-performance column-oriented database used heavily in finance for storing and analyzing time-series data. Q combines the expressive power of the APL family of array languages with an SQL-like query dialect, all running on top of an extraordinarily compact runtime. Its design objectives are expressiveness, speed, and efficiency — qualities that have made it a fixture on Wall Street trading floors.

History and Origins

Q’s lineage runs straight through the APL tradition. Arthur Whitney, a Canadian computer scientist, was introduced to APL at age 11 by its inventor, Kenneth Iverson, a family friend. Whitney later worked alongside Iverson and Roger Hui at I. P. Sharp Associates, then moved to Morgan Stanley, where he helped develop A+, a variant of APL aimed at financial applications.

In 1993, Whitney left Morgan Stanley, created the first version of the K language, and co-founded Kx Systems to commercialize it. K is a dense, single-character-heavy array language in the APL mold. In 1998 Kx released kdb, a column-oriented database built on K that included ksql, an SQL-like query layer.

The pivotal moment came in 2003 with the release of kdb+, a 64-bit rewrite of the database built on the fourth generation of K (often called k4). Released alongside it was q: a language layer, defined in terms of k, that wraps k’s famously cryptic primitives in more readable, English-like keywords and adds an SQL-style query syntax. Where k might express an operation as a string of overloaded symbols, q offers named functions and select/exec/update statements — making the underlying power of the array engine far more approachable while still compiling down to the same fast core.

Design Philosophy

Q embodies several principles inherited and refined from the APL family:

  • Arrays first. The fundamental unit of computation is the list (vector). Operations apply across whole arrays rather than element-by-element, which both shortens code and maps naturally onto efficient, vectorized execution.
  • Brevity as a feature. Q programs are strikingly short. A complete analytic that might take dozens of lines in a conventional language is often a single line of q. Proponents argue this conciseness keeps entire problems within a programmer’s working memory.
  • A unified language and database. Q is not a language that talks to a database — it is the database’s language. Tables, dictionaries, and keyed tables are first-class data structures, and qSQL queries operate directly on in-memory and on-disk data.
  • Time-series orientation. The language and kdb+ are built for ordered, timestamped data, with constructs (such as as-of and window joins) tailored to matching and aggregating events across slightly differing timestamps.

Key Features

Q’s building blocks are atoms (scalars), lists, and functions, from which richer structures are composed:

  • Dictionaries, tables, and keyed tables as native data types.
  • qSQL, a query syntax resembling SQL but adapted to column-oriented storage, including specialized joins like the as-of join (aj) for aligning records with the most recent prior observation — a workhorse for matching trades to quotes.
  • Dynamic, strong typing: types are checked at runtime, but the system does not silently coerce incompatible values.
  • Functional programming with first-class functions and a family of higher-order operators (called adverbs/iterators, such as each, over, and scan) that replace explicit loops.
  • A tiny footprint. The kdb+/q interpreter is famously compact, which contributes to its cache-friendly performance.

A small flavor of q:

/ create a table of trades
trades:([] time:09:30:00 09:31:00 09:32:00; sym:`AAPL`AAPL`MSFT; price:150.1 150.4 280.2; size:100 200 50)

/ qSQL: total volume by symbol
select totalSize:sum size by sym from trades

/ functional style: square each element of a list
{x*x} 1 2 3 4 5

Evolution

Since its 2003 debut, kdb+ and q have advanced steadily while keeping the language remarkably stable:

  • kdb+ 3.0 (September 2012) added WebSocket support and a native GUID/UUID type, among other enhancements.
  • kdb+ 4.0 (March 2020) introduced multithreaded primitives, data-at-rest encryption, and support for Intel Optane persistent memory.
  • kdb+ 4.1 (stable, February 2024) brought multithreaded CSV/binary loading, the ability to nest parallel peach statements with a work-stealing scheduler, and substantially higher socket throughput.

Performance figures published by KX are best read with their benchmark context. For example, KX reported that socket operations in 4.1 delivered roughly a five-fold throughput increase over the prior version under high-volume connection workloads; such numbers reflect specific internal benchmarks rather than universal guarantees.

The corporate story evolved too. First Derivatives acquired a majority stake in Kx Systems in 2014 and full ownership by 2018, after which the broader company rebranded around the KX name. Whitney and co-founder Janet Lustgarten then founded Shakti Software to build a next-generation array database.

Current Relevance

Q remains the dominant analytics language in its niche: high-throughput, low-latency time-series processing in capital markets. Nearly every major investment bank, along with many hedge funds and high-frequency trading firms, runs kdb+/q somewhere in its data stack — for tick capture, backtesting, real-time analytics, and trade surveillance. Fluency in kdb+/q is a sought-after and well-compensated specialization in financial technology.

KX has also worked to broaden q’s reach beyond finance into telecommunications, energy, and IoT/sensor analytics, and has layered cloud and enterprise products on top of the core engine. A free non-commercial edition and the long-running online tutorial Q for Mortals have helped newcomers approach a language that can otherwise look impenetrably dense.

Why It Matters

Q demonstrates how far the array-programming paradigm — born with Iverson’s APL in the late 1950s — can be pushed into a modern, commercially essential tool. By wrapping the cryptic power of k in a more legible, SQL-flavored language, Whitney made vectorized, time-series computation accessible enough to dominate an entire industry while preserving the speed that made it valuable in the first place. For anyone curious about how a sixty-year-old idea about computing on arrays still shapes the systems behind global financial markets, q is one of the clearest and most consequential answers.

Timeline

1993
Arthur Whitney leaves Morgan Stanley and develops the first version of the K language, an APL-influenced array language, and co-founds Kx Systems to commercialize it. K is the foundation on which q would later be built.
1998
Kx Systems releases kdb, a column-oriented in-memory database written in K. It includes ksql, an SQL-like query layer that foreshadows q's later query syntax.
2003
kdb+ is released (around June 2003) as a 64-bit rewrite based on the fourth generation of K. Alongside it, Kx introduces q — a more readable, English-like wrapper language defined in terms of k — as the native language of kdb+.
2004
Kx releases the kdb+tick framework for capturing and storing real-time market data, helping establish kdb+/q as a standard for financial tick databases.
2007
kdb+ adds support for Mac OS X (around April 2007), complementing its existing Linux, Windows, and Solaris builds.
2012
kdb+ 3.0 is released (September 2012), adding features such as WebSocket support and a native GUID/UUID type.
2018
Arthur Whitney and Janet Lustgarten complete the sale of their remaining shares in Kx Systems to First Derivatives, which had taken a majority stake in 2014. Whitney goes on to found Shakti Software to develop a successor array-database system.
2020
kdb+ 4.0 is released (March 2020), introducing multithreaded primitives, data-at-rest encryption, and support for Intel Optane persistent memory.
2024
kdb+ 4.1 reaches stable release (February 2024), bringing improvements such as multithreaded data loading, nested parallelism via peach, and higher socket throughput.

Notable Uses & Legacy

Investment banks

Major banks — reportedly including Goldman Sachs, Morgan Stanley, J.P. Morgan, UBS, and Deutsche Bank — use kdb+/q to capture, store, and analyze high-volume market data for trading and risk.

High-frequency trading firms

HFT shops and quantitative hedge funds rely on q for backtesting strategies and running fast time-series analytics over enormous tick datasets where latency is critical.

Exchanges and market data

Exchange and market-data operators have used kdb+/q to process order-book and trade feeds, including NYSE/Euronext-related data handling.

Surveillance and compliance

Financial institutions apply q to trade surveillance and market-abuse detection, scanning large historical and real-time datasets for anomalous algorithmic and high-frequency trading patterns.

Telecom, energy, and IoT analytics

Beyond finance, KX has applied kdb+/q to time-series workloads in telecommunications, energy markets, and sensor/IoT data, where high-throughput temporal analytics are valuable.

Language Influence

Influenced By

Running Today

Run examples using the official Docker image:

docker pull
Last updated: