Writing

Introducing Magpie: One Engine for the Many Ways You Read Data

Tables, streams, search, and vectors from one ordered history of writes

Data Systems · Crow · October 2026

An application often needs several ways to read the same data. It needs the current value of a record, the events that changed it, a search over its text, an aggregate over its columns, and perhaps the nearest embedding.

Those needs commonly lead to several systems, each holding its own representation of the data. The application then takes responsibility for moving updates between them, tracking their progress, and deciding what to do when they disagree.

Magpie brings these reads into one storage engine. Every write enters an ordered log. From the same underlying files, a program can read current state, consume changes, search text, find nearest vectors, compute grouped aggregates, and build point-in-time joins.

Magpie is written entirely in Crow and used as a Crow package. A log is a directory of immutable files. HTTP, Redis, and Kafka interfaces make selected capabilities available to other clients. Two packages built on the same engine ship with it: a knowledge graph and a machine-learning feature store.

The central design question is simple: how much can an application do with one ordered history of writes and one storage layout?

Application writes PostgreSQL transactions Kafka event streams Elasticsearch full-text search Redis cache ClickHouse analytics Vector DB embeddings Graph DB relationships Feature store ML features sync jobs · CDC · cache invalidation Several systems a copy of the data in each, kept in sync by the application Application writes once reads many ways Magpie Interfaces · read and write Crow calls HTTP Redis Kafka Built on the engine Knowledge graph graph walks, as-of reads ML feature store online, offline, training The engine Current state latest, lookup Change streams since, tail Full-text search search Vector search nearest Analytics summary Point-in-time joins prior Transactions commit, checked against the keys it read One ordered log · one file format One engine every write enters one ordered log, read in several ways
Illustrative Left: a common arrangement, with a copy of the data in each system and the application keeping the copies in sync. Right: Magpie serves the same kinds of reads from one ordered log. Crow programs call it directly, and HTTP, Redis and Kafka clients read and write through the protocols it implements; its knowledge graph and feature store are built on the same engine. It does not reproduce every feature of each system; its current limits are listed under Where Magpie fits.
Part 1

The idea

One example that shows what Magpie does.

One write, several ways to read

Consider an application that stores orders. Each order has an identifier, an item, a description, a quantity, and an embedding of its description for similarity search.

When an order changes, Magpie appends a new row and assigns it a position. The position establishes where that write belongs in the log.

The application can then ask different questions about those writes:

Question Magpie operation Explained in
What is the current state of each order? latest Current state and change streams
Which versions of this order remain in the log? lookup Current state and change streams
What changed after this position? since or tail Current state and change streams
Which descriptions match these words? search Full-text search
Which orders are most similar to this one, by embedding? nearest Vector search
What is the total quantity of each item? summary Analytics and point-in-time joins
What did each order look like at a given moment? prior Analytics and point-in-time joins

These operations share the stored data. An update does not need to be copied into a separate search service or analytics database before those readers can use it.

Retention is an explicit choice. A log can retain every row, or merging can compact it to the newest version of each key. That choice determines how much history remains available.

Part 2

Storage and consistency

How a write becomes a durable file, how files are laid out and compacted, and how transactions are checked.

The storage design

Magpie organizes storage around three components: a sequencer, immutable batch files, and merged segments.

The sequencer lives in memory. It assigns positions, holds pending writes, checks transaction conflicts, and maintains an index of the newest row for each key when needed.

A flush writes pending rows into a batch file . Each batch carries the rows' positions, sorts the rows by the log's keys, and stores them in columnar row groups.

A merge combines files into larger sorted segments. It can discard superseded versions and builds full-text postings into the resulting segments.

Clients Crow programs and pages the same process, or another by URL HTTP, Redis and Kafka clients through three servers written in Crow Files and S3 CSV, Parquet, JSON; backups Crow programs Queries table operations over reads; four run inside the reader Transactions keys read and rows written, checked in memory Consumers follow the log with since and tail, from a position Policy merges and retention, servers, backup, followers Sequencer In memory, per log: positions, pending rows, each key's last position and newest row a put gets its position at once · a commit is checked here · pending rows are flushed as one batch file Batch files Immutable batch files, numbered in arrival order · the manifest, replaced atomically each file is a log entry and a sorted, columnar segment with statistics · a snapshot is a position Segments Merged segments in levels same format, at most 1 GB each, with full-text postings Backups the live files plus a listing written last, to a folder or S3 Follower an asynchronous follower fetches the immutable files and reads them with the same operations · promotion is manual write read put, batch, commit a client's write flush: one file, synced merge copy read at a snapshot
Illustrative Writes flow down through the amber layers: into the sequencer, into a batch file at each flush, and into merged segments when the program merges. Reads go up from the segments, the batch files and the sequencer's pending rows.

Batch files and segments use the same format. Each file supports several access patterns:

  • Positions let consumers follow changes.
  • Key ordering, statistics, and Bloom filters let lookups skip irrelevant data.
  • Columnar chunks let analytical reads load only the columns they need.
  • Text can be searched directly in batches or through postings in merged segments.
A writer's rows a batch, or one flush's puts one write one flush Batch file N a position column: 1041 … 1163 rows sorted by the log's keys row groups of about 4 MB min, max, counts and a filter per chunk Magpie's own format written once, never changed Consumer at a position reads files from N on, in order: streams, change feeds Lookup by key, scan with statistics skips files and groups that cannot hold the key Search a batch read whole; a segment through its postings Merge many files → one sorted segment, same format, postings built as each group is written when the program asks
Illustrative One file serves every kind of reader. Each column chunk records its minimum, maximum, missing and distinct counts, and most also carry a Bloom filter (about 2% false positives), so a lookup opens only the files and row groups that can hold its key.

A row is written when it reaches a batch file and rewritten when a merge incorporates it into a segment. There is no separate durable write-ahead log or external search store.

Magpie's own file format

Magpie stores everything in one file format of its own, written for this engine: batch files, merged segments and the manifest are all files of this format. A file is written once and never changed. It holds a frame's columns in row groups, followed by an index that lets a reader find one column of one row group without reading the rest.

magic Row group 1 · about 4 MB chunk a chunk b chunk c Row groups 2 … the same shape Column blocks a b c Footer rows, positions, keys, columns length magic filter 1 2 3 4 1 Read the last bytes: the footer's length, and the magic that says this is a Magpie file. 2 Read the footer: the row count, the first and last positions, the keys and the columns. 3 Read one column's block: per group, where its chunk lies, min, max, missing and distinct counts. Skip groups that cannot match. 4 Read only the chunks of the columns asked, in the groups that are left, and decode them across the cores.
Illustrative How a reader opens a file: the end first, then only what it needs. Asking for two columns of a hundred reads two columns' blocks and chunks.

How a column is stored

A row group holds about 4 MB of rows, and at least 1,024. Within it, each column is one chunk, encoded by its type:

Column Encoded as
Integers Offsets from the minimum, or deltas from the previous value, whichever is smaller, bit-packed. A column of positions or timestamps takes a few bits a row.
Floats Their 64 bits, or 32 for a column the log declared narrow
Text Lengths and bytes, or a dictionary and codes when at most half the values are distinct
Booleans A bitmap
Moments Milliseconds and a UTC offset
Vectors The rows' numbers laid end to end, 64 or 32 bits each
Missing cells A presence bitmap beside any of the above

Each chunk then goes through an LZ77 compressor written for Magpie, which is kept only where it saves at least about a tenth of the bytes.

What lets a reader skip data

  • Statistics. For each column of each row group, the column's block records the minimum, the maximum, and the missing and distinct counts. A reader skips any row group whose range cannot hold what it is looking for.
  • Bloom filters. After each chunk comes a filter over the group's distinct values: 8 bits and 6 hashes per value, about 2% false positives. It is left out past 65,536 distinct values, and for the position column, whose minimum and maximum already prune a range.
  • Full-text postings. Merged segments add, for each text column, a filter over its words and the postings described under full-text search.

Why not Parquet or Arrow

Parquet keeps one footer that describes every column chunk of every row group, and a reader parses it whole before reading any column; on a wide, long table that footer grows large. Magpie's footer holds one small entry per column, pointing at that column's block of per-group entries, so a reader of two columns out of a thousand reads the footer and two columns' blocks. Magpie's chunks also match how a Crow frame holds its columns, so writing and reading need no conversion through another in-memory format. Programs that need Arrow, Parquet, CSV or JSON load and save them through Crow's table library.

The manifest uses the same format: a one-group file that lists the live segments and what the log declared, replaced atomically when a merge finishes.

Visibility, durability, and snapshots

Magpie distinguishes a write becoming visible from a write becoming durable.

Write operation Visible in the writing process Durable
put Immediately After a flush
batch During the call Before the call returns successfully
commit If accepted Before the call returns successfully

A compiled program flushes puts on a background thread. Writes arriving during a flush join the next batch. Under the interpreter, the flush runs synchronously.

A process crash can lose pending puts. Programs that require durability before proceeding use batch , commit , or an explicit sync .

A flush writes the batch under a temporary name, syncs it to the disk ( F_FULLFSYNC on macOS, which also empties the drive's cache), links it to its final name, and syncs the directory. The link fails if the name is taken, so two writers can never claim one batch number. Recovery replays nothing: a temporary file is never listed, and a file cut short is refused with a reason.

Put a row, an event, a counter Commit rows, with the keys read Batch a bulk load, a backfill Sequencer positions given as rows arrive each key's last position each key's newest row a commit checked here, in memory pending rows flushed as one file The log batch 17 · 1041 – 1163 batch 18 · 1164 – 1290 batch 19 · 1291 – 1300 pending · 1301 – 1309 manifest each batch sorted by key, with its statistics; one order for every write flush a put and a flush, synced before it returns Segments Consumers merge tail Reader snapshot S S = position 1305 pending rows, batches and segments at or before S
Illustrative Every write takes its place in one order. A put is visible at once and durable at the next flush; a commit is checked in memory, then written and synced; a batch is a put and a flush, on disk before it returns. A reader bounded at position S sees exactly the writes at or before S.

Positions also define read boundaries. Reads using the same snapshot position share the same boundary on visible writes within a log. A table read, a change read, and an aggregate can therefore be evaluated against the same position, through their upto bound. search , nearest , and lookup read the log as it stands when they run.

Historical reads additionally depend on retention. Once compaction removes an older version, its position cannot restore it. Logs that need complete replay or historical reconstruction must retain every row.

A second machine can follow a log: it fetches the immutable files it lacks and reads them with the same operations. Shipping is asynchronous, so a write lives on the leader's disk alone until the follower's next fetch. Promotion is manual; automatic election and fencing are not implemented.

What a merge changes

A merge is an explicit operation controlled by the program.

It streams sorted inputs into new segments, builds full-text postings, and publishes the new file set through an atomically replaced manifest.

Batch file 17 sorted by key Batch file 18 sorted by key Batch file 19 sorted by key Streaming merge one row group from each input in memory rows in key order, then position keeps the newest version of each key, or every row Segment, level 1 same format, at most 1 GB full-text postings per row group statistics and filters per chunk Manifest replaced atomically; then inputs removed Levels eight level-1 segments one level-2 When a level holds more than eight segments, its oldest eight fold into one segment of the next level, so each merge rewrites only a slice of the log.
Illustrative The merge holds one row group per input, so its memory stays small whatever the log's size. Readers see either the old file set or the new one, never a mix, because the manifest switches in one step.

The retention mode determines what survives:

Retention mode Result
Keep the newest version per key Current state survives; superseded history can disappear.
Keep every row ( every = true ) Historical versions and replay remain available.

After compaction, a change consumer sees surviving rows at their original positions, with gaps where older versions were removed.

This makes retention part of the application's data model. A current-state log and a historical event log can use the same engine while choosing different merge behavior.

Transactions over keys

Magpie supports optimistic transactions within one log.

A transaction reads at a snapshot, records the keys it read—including keys it checked but did not find—and submits its writes. The sequencer refuses the commit if a recorded key changed after that snapshot. A refused commit writes nothing, and its error names the key and where it changed. An accepted commit lands as one batch and is on disk before the call returns.

 stale = magpie.commit['stock', frame.new[id = [2], qty = [26]],
    seen = 1, columns = ['id'], equal = ['2']]
log[stale.reason]
--- conflict: id = 2 was written at position 2, after snapshot 1 
The log Writer B Transaction A positions 0–1 id 1 qty 10 · id 2 qty 20 position 2 id 2, qty 25 position 3 id 2, qty 26 put id 2 qty 25 read at snapshot 1 id 2 → qty 20 commit, seen = 1 keys read: id = 2 refused · nothing written id 2 was written at 2, after snapshot 1 retry read at snapshot 2 id 2 → qty 25 commit, seen = 2 keys read: id = 2 accepted: position 3 synced before it returns time
Illustrative The positions and the refusal are from a real run, the same in both of Crow's modes. Transaction A reads id 2 at snapshot 1. Writer B then writes id 2 at position 2. A's commit names id 2 and snapshot 1, so the sequencer refuses it and nothing is written. A reads again at snapshot 2 and commits; its row lands at position 3, on disk before the call returns.

This supports transactions whose dependencies can be expressed as explicit keys. For example, an application can read an inventory record and submit an updated quantity, with a conflict if another write changed that record first, as in the figure. When the keys read are the log's own keys, the check runs against the sequencer's in-memory index of each key's last position.

For transactions that name every key they read, the result is serializable: no interleaving of two such transactions can slip past the check. After a refusal, the application reads again at a newer snapshot and retries. A retry is also safe after a crash: if a commit succeeded but its acknowledgement was lost, the same commit sent again is refused, because its own first write now comes after its snapshot. A transaction is never applied twice.

The check does not cover arbitrary predicates. A question such as "does any booking overlap this interval?" needs a key-based representation of the conflicting slots, such as one key per time slot the booking covers, if the application wants those conflicts detected.

A transaction covers one log, and each log has one writing process.

Part 3

Querying the log

Every way of reading the log, from a key's current value to search, vectors and analytics.

Current state and change streams

This section covers the basic reads, current state and change streams; the next three cover full-text search, vector search, and analytics with point-in-time joins. Every read returns a Crow frame, the language's in-memory table, and takes only what it needs from a file: the footer first, then the column blocks and chunks it asks for, as the file-format section describes.

The log id 1, qty 3 position 0 id 2, qty 12 position 1 id 3, qty 7 position 2 id 2, qty 20 position 3 not written yet position 4 latest the newest row of each key 3 7 20 [3, 7, 20] lookup id = 2 every version of the key 12 20 [12, 20] since 2 every row from position 2 7 20 [7, 20] tail after 3 waits for new rows waits the next rows
Illustrative Four reads of the same log, which the example below runs. Each selects different rows: the newest version of each key, every version of one key, everything from a position, or whatever arrives next.
reads.co
 use magpie, frame
 
a = magpie.batch['orders', frame.new[id = [1, 2, 3], qty = [3, 12, 7]], by = ['id']]
b = magpie.put['orders', frame.new[id = [2], qty = [20]]]
log[magpie.latest['orders'].qty]
log[magpie.lookup['orders', ['id'], ['2']].qty]
log[magpie.since['orders', 2].qty]
log[len[magpie.tail['orders', 3, 0.1]]] 
Output
 [3, 7, 20]
[12, 20]
[7, 20]
0 

The last line waits a tenth of a second for rows past position 3; none arrive, so it answers an empty frame.

Current state: latest and lookup

latest answers the table a log holds: the newest version of each key. It can be bounded to a range of the first key, so a segment sorted that way reads only the row groups the range covers, or to a snapshot position with upto . Given one key, it answers from the sequencer's memory in microseconds. lookup answers every version of a key that the log still holds. It opens only the files whose filters admit the key, and in a segment only the row groups whose statistics do, so a lookup by a segment's sort keys reads only the row groups that hold them.

Change streams: since and tail

since answers every row from a position onward, in position order: a consumer reads from the position after the last one it saw. Reads are bounded windows, so a consumer walks a large log a window at a time. tail answers the rows after a position, waiting up to a given number of seconds for new ones to arrive (it checks every 20 ms), so a view that follows the log is a loop over tail . Kafka consumers reach the same reads through the Kafka protocol, and after a merge a consumer sees the surviving rows at their original positions.

Four reads would need too much data if they were computed after a read returned: full-text search, vector search, analytics and point-in-time joins. Magpie runs them inside the reader, one row group at a time, as the next three sections describe:

Load first what Magpie avoids the whole log every row and column, held as one frame in memory then compute a small answer Inside the reader row group skipped row group row group skipped row group batch files and segments skipped where statistics or filters rule them out one group at a time summary decode the named columns, filter, group → partial counts, sums, means and variances search postings, or a scan of a batch → the best-scoring rows blocks that cannot reach the top k are skipped nearest the cosine similarity of each vector → the k best rows so far prior each key's run of rows → the newest at or before each label's moment Combined into one row per group the top k rows, with scores the k nearest, with scores one row per label
Illustrative Instead of loading the whole log as a frame and then computing, each operation works inside the reader, one row group at a time. Groups that statistics or filters rule out are skipped, only the needed columns are decoded, and small partial results are combined into the answer.

Vector search

A frame column can hold vectors of one width, such as embeddings, stored as 64-bit floats, or as 32-bit for a column the log declares narrow . nearest returns the k rows whose vectors have the highest cosine similarity to a query vector, computed exactly over every row, pending rows included. It agrees row for row and score for score with the flat index of Crow's vectors package. Among 100,000 vectors of width 64, the nearest 10 took 22 ms from the files, against 12 ms for that flat index over the same vectors held in memory. An approximate index such as HNSW is planned for collections where an exact scan is too slow.

x y id 1 · [1, 0] · 0.995 query [1, 0.1] id 3 · [1, 1] · 0.774 id 2 · [0, 1] · 0.10 cosine to the query; the top 2 are ids 1 and 3 Every row group batch files, segments and pending rows Cosine with the query the inner product of unit vectors, for every row Keep the k best here k = 2: ids 1 and 3 Rows with a score best first; exact, with no index to build
Illustrative Left, to scale: the example's three vectors and the query, with each one's cosine similarity. Right: how nearest finds them, an exact scan that keeps the k best.

For example, the two vectors nearest [1.0, 0.1] among three:

vectors.co
 use magpie, frame
 
a = magpie.batch['vecs', frame.new[id = [1, 2, 3],
    e = [[1.0, 0.0], [0.0, 1.0], [1.0, 1.0]]], by = ['id']]
log[magpie.nearest['vecs', 'e', [1.0, 0.1], 2]] 
Output
 id       e  _pos               score
int  vector   int               float
--  ------  ----  ------------------
 1  [1, 0]     0  0.9950371902099893
 3  [1, 1]     2  0.7739572992033211
 
[2 rows x 4 cols] 

Analytics and point-in-time joins

Analytics

summary computes count, sum, minimum, maximum, mean, variance, standard deviation, and first and last values, grouped by key columns. It can filter by a column compared with a value (equal, not equal, less than and so on), by a range of the first key, and by a position bound. Each row group is pruned by its statistics, decoded for the named columns only, filtered and grouped into partial results, and the partials are combined, the variance by Welford's and Chan's methods. The answer equals Crow's own group over a full scan of the same rows, up to the last digits a different summation order moves.

Row group 1 · day 1 A · px 10 · vol 1 B · px 20 · vol 2 Row group 2 · day 2 A · px 12 · vol 3 B · px 22 · vol 4 group group Partials A · n 1 · Σpx 10 · Σvol 1 B · n 1 · Σpx 20 · Σvol 2 Partials A · n 1 · Σpx 12 · Σvol 3 B · n 1 · Σpx 22 · Σvol 4 combine The answer A · mean px 11 · total vol 4 B · mean px 21 · total vol 6 only px and vol are decoded; no group's rows are kept once its partials are made
Illustrative How summary computes the example below. Each row group is reduced to partial results per key, and the partials are combined into the answer. In this tiny example both days fit in one row group; the split shows how a larger log's groups combine.

The mean price and total volume per symbol, computed inside the reader:

summary.co
 use magpie, frame
 
b = magpie.batch['bars', frame.new[day = [1, 1, 2, 2],
    sym = ['A', 'B', 'A', 'B'], px = [10.0, 20.0, 12.0, 22.0],
    vol = [1, 2, 3, 4]], by = ['day', 'sym']]
log[magpie.summary['bars', ['sym'], ['px', 'vol'], ['mean', 'sum']]] 
Output
 sym  px_mean  vol_sum
str    float      int
---  -------  -------
  A       11        4
  B       21        6
 
[2 rows x 3 cols] 

Point-in-time joins

prior is an as-of join. Given a frame of labels, each holding the log's keys and a moment, it finds for each label the newest log row with the same keys at or before that moment, reading each key's run of rows in the sorted segments; a label with no earlier row gets missing cells. Given upto , it also ignores rows written after a position, so a training set built as of a position is identical every time it is rebuilt, provided the log kept the versions it read. The feature store's training sets are built this way and checked cell for cell against pandas's merge_asof .

Symbol A Symbol B 0 5 10 15 20 25 30 time px 1.0 px 2.0 px 5.0 label A at 25 → px 2.0 label A at 5 → missing label B at 12 → missing
Illustrative The example below on a timeline. Amber squares are log rows and blue circles are labels; each label takes the newest row of its symbol at or before its own moment, and gets missing cells where there is none.

In the example below, the label for A at 25 gets A's row from 20. B at 12 gets missing cells, because B's only row comes later, at 15, and A at 5 comes before A's first row.

asof.co
 use magpie, frame
 
c = magpie.batch['prices', frame.new[sym = ['A', 'A', 'B'],
    t = [10, 20, 15], px = [1.0, 2.0, 5.0]], by = ['sym'], time = 't']
labels = frame.new[sym = ['A', 'B', 'A'], t = [25, 12, 5]]
log[magpie.prior['prices', labels]] 
Output
 sym   t       px
str  int    float
---  --  -------
  A  25        2
  B  12  missing
  A   5  missing
 
[3 rows x 3 cols] 

These operations make the log useful for application state, retrieval, analytics, and training-data construction.

Part 4

Packages and protocols

What is built on the engine, and how programs outside Crow reach it.

Built on the engine: a knowledge graph and an ML feature store

Two packages in Magpie's repository are written entirely on the engine's operations, each in a few hundred lines of Crow. They show what the shared log makes cheap: history, point-in-time reads and similarity search come with the storage instead of being built beside it.

Knowledge graph · kg works_at works_at knows alice acme bob stored as Magpie logs nodes by id label, properties edges by src, rel, dst weight, provenance back by dst, rel, src the edges reversed vectors by id node embeddings neighbors · inbound · walk · path · match · subgraph asof (through prior) · similar (through nearest) · rules that derive edges removals are tombstones; every read can take a past position ML feature store · features Source events any Magpie log backfill: windows stream: the tail Feature function one Crow function append Feature group one log, keyed by entity, with event time latest history prior Online newest row per entity, from memory Offline the history, read by position Training sets labels joined as of each label's moment one function for backfill and stream: training and serving compute features alike
Illustrative Left: kg keeps a graph as four Magpie logs (nodes, edges, the edges reversed, and node embeddings), so each graph read is a Magpie read of one of them. Right: a feature group is one log; one function fills it from a source log by backfill or by stream, and the same log serves the online value, the offline history and point-in-time training sets.

Knowledge graph

kg keeps a graph's nodes and edges as Magpie logs under one directory. Edges are keyed by source, relation and target, with a weight and the fact's provenance, and are written a second time keyed by target, so a node's outgoing and incoming edges are each one key's run in a sorted segment. Removing a fact writes a tombstone, and every read takes a position, so the graph can be read as it stood at any point in its history.

On that base, kg answers neighbors, breadth-first walks, shortest paths, pattern matches joined on shared variables, rules that derive new edges, and the edges as they stood at each row's moment. Node embeddings live in a fourth log, so an entity can be found by meaning with similar and then expanded through its edges. A subgraph can be handed to Crow's graph package for PageRank, connected components and shortest paths.

ML feature store

features makes a feature group a log keyed by its entity, with its event time declared. One write then serves both sides of a feature store: the online value is the entity's newest row, read from the sequencer's memory, and the offline history is the log itself. No job copies one into the other.

A feature is defined once, as one Crow function. The same function runs over windows of the source log for a backfill and over its tail for streaming, so training and serving compute features the same way. A training set joins labels to each feature group as of each label's moment, through prior ; given a position, it comes out identical at every rebuild. Embeddings are features like any other, and a registry log records what each feature means and which function computes it.

Package capability Magpie operations underneath
Graph history and time travel Tombstone rows, and every read bounded by upto
A node's edges, walks and paths Key-sorted logs: a node's edges are one key's run, and a walk reads each hop as one key range
Edges as of a moment; training sets prior , the as-of join
Similar entities; embeddings as features nearest over a column of vectors
Online feature reads latest of one key, from the sequencer's memory
Streaming features tail , the rows past a position

The feature store's training sets are checked cell for cell against pandas's merge_asof .

Three network protocols: HTTP, Redis, and Kafka

Crow programs call Magpie inside their own process. For everything else, Magpie implements three network protocols itself, each a small server written in Crow:

  • HTTP carries Magpie's own operations. A request names a log and an operation such as latest , search or put , and rows travel as JSON.
  • Redis's protocol (RESP2) lets Redis clients use Magpie as if it were a Redis server.
  • Kafka's protocol lets Kafka producers and consumers use Magpie as if it were a Kafka broker.

No Redis or Kafka runs anywhere, and nothing copies data from one into Magpie. The engine underneath is Magpie's in every case: a Redis key and a Kafka topic are both Magpie logs, so a Crow program can read, search and aggregate the same data the other clients write.

curl, any HTTP client GET and POST, JSON rows Another Crow program the same calls, given a URL redis-cli, Redis libraries the Redis protocol, RESP2 Kafka producers, consumers the Kafka protocol Magpie HTTP server magpie.door · Magpie's own operations Redis server redis.serve · Redis commands on Magpie logs Kafka server kafka.serve · Kafka requests on Magpie logs shop/orders any log, by its name cache/_kv and streams a row per write events/orders a log per topic, _groups, _offsets one engine underneath: no Redis or Kafka runs anywhere
Illustrative Each protocol is a small server inside Magpie, written in Crow. HTTP carries Magpie's own operations; the Redis and Kafka servers turn those systems' commands into reads and writes of Magpie logs.

HTTP: Magpie's operations over the network

The HTTP server exposes the operations a Crow program calls. A request's path names the log and the operation, the query string carries the arguments, and a POST body carries rows as JSON records:

  • GET for reads: latest , lookup , since , scan , search , nearest , summary , head , and the catalog ( batches , metrics ).
  • POST with rows for writes and joins: put , batch , commit , prior .
  • POST with no body for merge and sync .

Answers are JSON. A refused request gets status 400 with the reason, and an unknown log or operation gets 404. Another Crow program can pass the server's URL wherever it would pass a directory, and the same calls travel over HTTP.

server.co
 use magpie, frame
 
made = magpie.batch['shop/orders', frame.new[
    id = [1, 2], qty = [3, 12]], by = ['id']]
served = magpie.door['shop', 9001] 
client.co, another process
 use magpie
 
log[magpie.latest['http://localhost:9001/orders'].qty]
--- [3, 12] 
A terminal
 $ curl 'localhost:9001/orders/latest'
[{"_pos":0,"id":1,"qty":3},{"_pos":1,"id":2,"qty":12}]
 
$ curl 'localhost:9001/orders/lookup?on=id&equal=2'
[{"_pos":1,"id":2,"qty":12}] 

All three servers listen on localhost by default, and none has authentication or TLS built in.

The Redis protocol

Magpie's Redis server speaks RESP2, the protocol redis-cli and Redis client libraries use, so they connect to Magpie unchanged. Keys and values live in one Magpie log under the server's root, named _kv , with a row per write. A read is answered from the sequencer's in-memory index of each key's newest row, so a GET is a memory lookup, as it is in Redis. Streams are logs of their own, and a stream entry's id is its position in that log.

redis-cli or any Redis library RESP2 Redis server redis.serve one loop, every connection SET, MSET, INCR, DEL The _kv log a row per write: key, value, deleted flag GET, MGET, EXISTS A key's newest row from the sequencer's memory KEYS, DBSIZE Every key's newest row the latest of the _kv log XADD A log per stream the entry id is the position XRANGE, XREAD, XLEN Reads by position since and scan
Illustrative How Redis commands map onto Magpie. Writes become rows in the _kv log or in a stream's log; reads come from the sequencer's memory or by position.

Starting the server takes one line, and redis-cli works against it unchanged:

server.co
 use magpie.redis
 
served = redis.serve['cache', 6380] 
A terminal
 $ redis-cli -p 6380 SET greeting hello
OK
$ redis-cli -p 6380 GET greeting
"hello"
$ redis-cli -p 6380 INCR visits
(integer) 1 

A SET is a Magpie put: visible at once, and on disk at the next flush. Because the keys are an ordinary Magpie log, a Crow program can also read a key's history, search the values, or aggregate them with the operations described earlier.

Not supported yet: EXPIRE and TTL (Magpie has no expiry column yet), lists, hashes, sets and sorted sets, pub/sub, MULTI and Lua scripts, and XREAD's BLOCK option. KEYS takes * or a single key, and XADD takes * ids only.

The Kafka protocol

Magpie's Kafka server answers as a Kafka 0.10.1 broker does. A Kafka client first asks the broker which protocol versions it speaks and then uses those, so producers and consumers connect to Magpie unchanged; it is tested with the kafka-python client. Each topic is a Magpie log with one partition, and a record's offset is its position in that log. Consumer groups keep their memberships and committed offsets in two more logs, _groups and _offsets .

Producers kafka-python and others Consumer group reads from its offset Produce records join, commit Kafka server kafka.serve a 0.10.1 broker's protocol append, synced fetch events/orders one partition offset = position _groups members and generations _offsets committed offsets Crow programs since, search, summary
Illustrative A topic is a Magpie log. A produce appends to it and is acknowledged once the batch is on disk, a fetch reads from an offset, and consumer groups keep their state in two more logs. Crow programs read the same topic as any other log.
Kafka In Magpie
A topic A log under the server's root, with one partition
An offset The record's position in that log
Produce The records appended as one batch, on disk before the acknowledgement
Fetch The rows from an offset, at most 1,000 at a time; with nothing new, the server waits up to the client's max_wait_ms
Consumer groups Joins, rebalances and heartbeats, with members kept in the _groups log
Committed offsets The _offsets log
Compressed messages gzip and Snappy, decoded by Magpie's own Crow code

With the server started by kafka.serve['events', 9093] , a producer and a consumer group written with kafka-python 3.0.11 work as they would against Kafka, and a Crow program reads the same records as a Magpie log:

client.py
 from kafka import KafkaProducer, KafkaConsumer
 
producer = KafkaProducer(bootstrap_servers='localhost:9093')
for key, value in [(b'o1', b'created'), (b'o2', b'created'),
                   (b'o1', b'shipped')]:
    meta = producer.send('orders', key=key, value=value).get(timeout=15)
    print('produced at offset', meta.offset)
producer.close()
 
consumer = KafkaConsumer('orders', bootstrap_servers='localhost:9093',
                         group_id='billing', auto_offset_reset='earliest',
                         consumer_timeout_ms=5000)
for msg in consumer:
    print(msg.offset, msg.key.decode(), msg.value.decode())
consumer.close() 
Output
 produced at offset 0
produced at offset 1
produced at offset 2
0 o1 created
1 o2 created
2 o1 shipped 
read.co
 use magpie
 
log[magpie.since['events/orders', 0, -1, ['key', 'value', '_pos']]] 
Output
 key    value  _pos
str      str   int
---  -------  ----
 o1  created     0
 o2  created     1
 o1  shipped     2
 
[3 rows x 3 cols] 

A produce is acknowledged only after its batch is on disk. A client that retries after a lost acknowledgement appends the records again, so delivery is at-least-once, as with a Kafka producer that is not idempotent.

Not supported yet: the newer record format (magic 2) and its headers, LZ4 and Zstandard compression, more than one partition per topic, SASL and TLS, idempotent and transactional producers, and the topic-administration requests (a topic is created when it is first used). Record values must be UTF-8 text.

Part 5

In practice

Measurements, a complete example, where Magpie fits today, and availability.

Early measurements

Initial measurements used an Apple M4 Max with 64 GB of memory.

A market-data dataset contained approximately 11.3 million bars and 19.2 million quotes. Merging produced a 289 MB segment for the bars and a 240 MB segment for the quotes.

Representative reads from the files included:

Measured October 30, 2026

Operation Measured time
One symbol's day as minute candles with running volume-weighted price 10 ms
Last price, high, and volume up to an instant 11 ms
Top 20 symbols by daily volume 38 ms
Monthly volume grouped by day over 11.3 million rows 108 ms
Top 10 for a common word over 100,000 short texts, through the index 17 ms
Exact nearest 10 among 100,000 vectors of width 64 22 ms
Knowledge-graph walk of three hops, reaching 1,022 of 5,000 nodes 29 ms

How measured: compiled programs ( crow build ), each time the warm median, from the call to the answer in hand, with the data read from the files at every run. The answers to the price, top-20 and monthly-volume questions matched those of the ClickHouse database the data came from.

These are early measurements on one machine with datasets that fit in memory. They do not establish performance beyond memory capacity or under many concurrent clients.

Durable single-write latency is another important limit. A batch that reached disk before returning took about 13.4 ms on the measured machine, largely due to flushing the file and its directory. Grouping durable commits into shared flushes is a planned improvement.

A small example

Crow uses square brackets for function calls. This program creates an orders log, updates an order, and reads the same data in several ways:

orders.co
 use magpie, frame
 
first = magpie.batch['orders', frame.new[
    id = [1, 2],
    item = ['apples', 'pears'],
    note = ['a crate for the shop', 'pears for the kitchen'],
    qty = [3, 12]], by = ['id']]
 
second = magpie.put['orders', frame.new[
    id = [2, 3],
    item = ['pears', 'plums'],
    note = ['more pears', 'plums for the kitchen table'],
    qty = [20, 7]]]
 
log[magpie.latest['orders']]
log[magpie.latest['orders', equal = ['2']].qty]
log[magpie.search['orders', 'note', ['kitchen table'], 3].item]
log[magpie.since['orders', 2].item] 
Output, interpreted and compiled
 id    item                  note  qty  _pos
int     str                   str  int   int
--  ------  --------------------  ---  ----
 1  apples  a crate for the shop    3     0
 2   pears            more pears   20     2
 3   plums  plums for the kit...    7     3
 
[3 rows x 5 cols]
[20]
['plums']
['pears', 'plums'] 

The current table contains three orders. Order 2 has quantity 20 because its newer row supersedes its earlier value.

The key read returns [20] . The phrase search returns ['plums'] . Reading changes from position 2 returns ['pears', 'plums'] .

Those results come from the same writes, including rows still pending in the writing process. log[x] prints x , and the program prints the same output whether Crow interprets it or compiles it.

Where Magpie fits

Today, Magpie suits applications that can keep a log on one machine and benefit from several access patterns over the same writes.

Its appeal is a smaller set of moving parts: current state, change consumption, search, vectors, and analytics share an engine and a storage format, and the knowledge graph and feature store are built from the same operations. Crow supplies the programming and query interface, and programs in other languages reach the same data over HTTP or the Redis and Kafka protocols.

A good fit today

  • An application whose data fits on one machine and that needs several of these reads over the same writes, such as current state, change streams, search and analytics.
  • Machine-learning pipelines that need online features and point-in-time-correct training sets from one write.
  • Services that use Redis or Kafka clients for keys, streams or events, within the commands and requests Magpie supports.

Current limits

The present boundaries are substantial:

  • One writing process per log.
  • Asynchronous followers with manual promotion; no automatic failover.
  • Transactions within one log, with key-based conflict checks.
  • Historical reads limited by the chosen retention policy.
  • Each durable write pays a full disk flush, about 13 ms on the machine measured.
  • Exact vector search only.
  • Explicitly scheduled merges.
  • Schema changes through a new log.
  • No SQL: queries are Crow programs, or HTTP calls to Magpie's operations.
  • Subsets of the Redis and Kafka protocols, and no authentication or TLS on any network interface.

What comes next

The next work includes shared flushes for durable commits, expiry, approximate vector indexing, newer Kafka records, and larger-scale measurements. Beyond these, the direction is a multi-node data platform: replication with election and fencing, and logs spread across machines.

Availability

Crow is open source at github.com/agncrow/crow.

Magpie is a Crow package at github.com/agncrow/magpie, source-available under the Business Source License 1.1. Its published terms allow development, testing, non-commercial use, and commercial production on one machine per application. Each version becomes Apache-2.0 four years after publication.

Magpie's organizing idea is one ordered set of writes that applications can read in several ways. The engine makes that idea concrete through a shared file format, explicit durability choices, and retention policies the program controls.