In developmentArcanum products are not released yet.Get launch updates →
ARCANUM
concepts

Designing topics

Every topic is a handful of choices: how many partitions, how many copies, how safe a write must be, what to keep and what to forget. This page explains each one, when it pays off and when it does not.

All examples follow one game, Metarealm, from our architecture series. A single meadow server runs the shared open field. Any number of realm servers run private dungeons. The servers never connect to each other: everything they share goes through Rune. Positions, gold, inventory, loot on the ground, portals and the question of which server owns a hero right now are all topics.

Topics: a log, not a table

A topic is an append-only log. Each record says which thing it is about (its key, such as a character id), what happened (its value), and gets a line number (its offset). Records are never edited in place. A hero who walks ten steps writes ten records; a hero who picks up a sword writes one more.

That sounds wasteful until you notice what it buys. Any server can read the log from the start and arrive at exactly the same state as every other server, because they all read the same records in the same order. That is how Metarealm's meadow server boots: it replays its topics, and the world is back. Everything on this page is a decision about how that log is split, copied, kept and checked.

Partitions: spreading the work

A topic is split into one or more partitions, each its own log with its own order. Records with the same key always land in the same partition, so everything about one hero stays in order. Records about different heroes may sit in different partitions, and there is no order between partitions at all.

Each partition is led by one broker, which takes its writes. Four partitions can be led by four brokers and written in parallel; a consumer group can hand each partition to a different worker. Partitions are how a topic grows past what one broker and one reader can carry.

create topic meadow_positions { id uint64, x float32, z float32, yaw float32 } partitions 4 key id with (cleanup.policy = compact); -- hundreds of heroes, a write every second each create topic meadow_gold { entryId uint64, characterId uint64, delta int64 } partitions 1 key entryId; -- one partition: a view adds it up

Positions are Metarealm's busiest topic, and nothing needs them in a global order: only each hero's own steps must stay in sequence. Four partitions it is. Gold is the opposite. A balance view sums every entry per hero, and a view that adds things up must see all of them in one place, so the gold ledger has exactly one partition.

more partitions when

One topic carries a lot of writes or needs several readers working side by side, and order only matters per key: positions, combat events, chat lines per channel.

one partition when

A view adds records up (count, sum, max), you need one order across every key, or the topic is small. Most of Metarealm's topics have one.

The count is fixed when the topic is created, and a record's partition comes from its key, so changing it later would scatter every key. Choose for the load you expect, not the load you have today. Each partition also costs memory, files and a leader, and a namespace may cap how many you get.

Replicas: surviving a lost broker

Replicas are copies of each partition on other brokers. One copy leads; the others follow it, record by record. When the leader's broker dies, an up-to-date follower takes over within moments and clients follow it there on their own. With one copy, a dead broker means the partition is gone until it comes back, or for good if its disk does not.

create topic character_location { characterId uint64, owner uint8, serverId uint32, ownerEpoch uint32 } partitions 1 replicas 3 key characterId with (cleanup.policy = compact); -- who owns each hero: never lose it

Copies are not free. Every write crosses the network to each of them and takes disk on each, and a write that waits for the copies (below) waits for the slowest one it needs. Rune keeps at least a majority, so on a three-broker cluster a topic has two or three copies; leaving replicas out puts one on every broker.

three copies when

Losing the data would hurt a player or the business: characters, inventory, gold, ownership. On a three-broker cluster that is every broker, so it is simply the default.

fewer when

You run a single broker in development, or the data can be rebuilt or is worthless soon: a cache, a heartbeat. Never fewer than the cluster's majority.

Write tiers: how safe is "done"

When a server writes a record, it waits for a yes. The tier decides when that yes comes. leader answers as soon as the leading broker has the record: the fastest, but a crash in the next instant can lose it. majority, the default, answers once most copies have it: a single lost broker loses nothing. strict also waits until those copies have saved it to disk, which survives even a power cut across the whole cluster, and costs a disk flush on every write.

create topic meadow_positions … with (tier = leader); -- losing one second of walking is fine create topic meadow_inventory … with (tier = majority); -- the default: a sword is never lost create topic gem_purchases … with (tier = strict); -- if Metarealm sold gems: on disk before we say yes

The question to ask is: if this write vanished, would anyone notice? A hero snapping back one step is invisible; the next position record fixes it a second later. A sword that disappears from a bag is a support ticket. A paid gem pack that disappears is a refund and a lost customer.

leader for

High-rate, self-healing data where the next record replaces the last: positions, spawn timers, telemetry.

majority or strict for

Anything a player owns or paid for. strict only where a whole-cluster power loss is a real risk and the write rate is modest.

Related: durability = all-in-sync makes a write wait for every up-to-date copy rather than most, for data you would rather pause than risk. The producer also picks how long it waits (Acks::Leader or Acks::All in the API).

Transient or persisted: memory or disk

A transient topic lives only in the memory of its copies. It is still replicated, so one broker restarting loses nothing, but it never touches the disk, and if every copy restarts, it starts empty. In exchange, it is as fast as Rune gets and costs no disk at all.

create transient topic realm_servers { serverId uint32, load uint16, lastBeat int64 } key serverId with (cleanup.policy = compact); -- heartbeats: stale in seconds create transient topic realm_tickets { characterId uint64, instanceId uint64, expires int64 } key characterId with (cleanup.policy = compact); -- one-time dungeon passes

Metarealm's realm servers announce themselves with a heartbeat every few seconds and hand heroes one-time dungeon tickets that expire in a minute. After a full restart, none of that is worth recovering: realms beat again, tickets get reissued. That is the test for transient: would you want this back after the lights go out?

transient for

Presence, heartbeats, matchmaking queues, short-lived tickets, live positions you also write elsewhere.

persisted for

Anything you rebuild the world from. Also needed for rules (unique, check) and autoincrement, which transient topics cannot have.

What to keep: retention or compaction

A log that only grows eventually fills the disk. Rune forgets in one of two ways. Retention (cleanup.policy = delete, the default) drops the oldest records once they pass an age or a size: a rolling window. Compaction (compact) keeps the newest record of every key and drops the older ones, so the topic becomes a table of current values that never loses a key. A record with an empty value, a tombstone, deletes its key.

create topic meadow_ground_items { itemId uint64, kind uint32, x float32, z float32 } key itemId with (cleanup.policy = compact); -- loot on the ground; picking it up writes a tombstone create topic combat_log with (retention.ms = 1209600000); -- two weeks of fights, for disputes create topic meadow_xp { entryId uint64, characterId uint64, delta int64 } key entryId; -- a ledger: delete policy, no limit, kept forever

Metarealm's ledgers are worth a second look. XP and gold are never stored as a balance that gets overwritten; each reward is a new entry with its own key, and a view sums them. Two rewards can never overwrite each other, and the full history of how a hero got rich is still there. The ledgers use the default delete policy with no age or size limit, so nothing is ever dropped.

compaction for

State: the current value per key. Characters, inventory slots, ground items, portals, ownership.

retention for

Events you need for a while and then never: combat logs, chat, analytics feeds. Pick an age or a size. With neither (the default), it keeps everything: a ledger.

Untyped, typed, keyed

An untyped topic carries bytes Rune never looks at: you choose the format, and Rune moves it. A typed topic has fields, and the broker checks every write against them, so a buggy server cannot poison the log with a malformed record. A typed topic with a key becomes a table: views can be built on it, rules can guard it, the broker can hand out ids, and rune schema generate writes the C++ type for it.

create topic analytics_raw; -- bytes: a client's own format create topic chat_lines { channel uint32, sender uint64, text string } partitions 4; -- checked, append-only create topic meadow_characters { id uint64 autoincrement, accountId uint64, name string(16), level uint16 } key id with (cleanup.policy = compact); -- a table

typed and keyed for

Almost everything in a game backend. It costs a schema, and buys checked writes, views, rules, generated code and safe schema changes.

untyped for

Data whose format you do not control or that Rune should not care about: an external feed, compressed blobs, a bridge from another system.

Schemas can change later. Adding a column makes a new version; old records stay readable in the version they were written with. See changing topics.

Views or consumers: asking or listening

There are two ways to read. A consumer listens: it receives every record as it is written, in order, and reacts. A view answers questions: the broker folds the records into a table as they arrive, and you look rows up by key. "Tell me whenever a hero levels up" is a consumer. "What is hero 42's gold right now?" is a view.

create view meadow_gold_balance key characterId as select sum(delta) as gold from meadow_gold; rune> select gold from meadow_gold_balance where characterId = 42; -- one lookup, always current

Without the view, a tool that wants hero 42's gold must read the whole gold ledger and add it up itself. With it, the answer is one lookup, always current, and persisted with checkpoints so a restart does not rebuild it from the beginning. Metarealm's dashboards and support tools read views; its game servers consume topics, because they rebuild their whole world in memory anyway.

a view when

Something needs a current answer by key: a balance, a profile, a character list, a count. Web tools, support desks, login services, other servers asking one question.

a consumer when

Something must act on every record: a game server rebuilding its world, a quest engine reacting to kills, a bridge copying data out. A consumer group shares the partitions between workers.

A view reads one topic. Adding things up needs that topic to have one partition, and the view only sees what is in the log: it cannot join two topics or call your code.

Rules: letting the broker say no

Two meadow servers are not a problem today, but picture two login servers. Both receive "create a hero named Ayla" in the same millisecond. Both check the name: free. Both write. Now there are two Aylas. Checking in your server cannot close that gap, because the check and the write are separate steps on separate machines.

A rule moves the check into the broker, which sees every write to a topic in one order. The second Ayla is refused and is never seen by any reader or view.

create unique view character_name key lower(name) as nameKey as select id from meadow_characters; -- one Ayla, in any case create view account_heroes key accountId as select count(*) as heroes from meadow_characters constraint max_heroes check (heroes <= 12); -- at most 12 heroes per account

a rule when

Several servers write the same topic and a mistake must be impossible, not just unlikely: unique names, caps per account, a key that must not exist yet.

check in your server when

The rule needs things a view does not have: another topic, the time, the hero's quest state, a call to a payment provider. Or one server owns the data, so there is no race to close.

Rules have edges worth knowing. A delete is never refused, so model money as entries added, not rows removed. A rule only compares a view's own columns with constants. Rules need a persisted topic. And the writer only learns why it was refused if it asks for the verdict (checked writes). The full behaviour is on the QL page.

Transactions: all or nothing

A hero picks up a sword from the ground. Two things must happen: the item leaves meadow_ground_items and appears in meadow_inventory. If the server crashes between the two writes, the sword is either duplicated or destroyed. A transaction groups writes across topics and partitions so that all of them become visible, or none do.

p.beginTransaction(); p.send(groundItems, Key(itemId), tombstone); // the sword leaves the ground p.send(inventory, Key(slotKey), sword); // and lands in the bag p.commitTransactionAndWait(); // both, or neither

Commits are checked against every rule on every partition they touch, so a trade that would break a rule fails as a whole, naming the record that broke it. That safety has a price: a round of votes at commit, rows locked until it ends, a retry when another writer touched the same key first (TxnConflict), and a cap of 4 096 records per partition.

a transaction when

Two or more writes must agree: loot into a bag, gold for an item, a hero handed from the meadow to a realm with its rewards, consume-then-produce with exactly-once delivery.

no transaction when

It is one record, which is already all or nothing. Several records on one partition: an atomic batch is cheaper. High-rate data like positions, where the next write fixes the last.

One limit: readers of a single partition never see half a transaction, but two views on different partitions may each be a moment apart. If that matters, keep what must change together on one partition.

Metarealm at a glance

TopicChoicesWhy
meadow_positions4 partitions · compact · leaderThe busiest topic; only the latest position matters; a lost second heals itself.
meadow_characters1 · compact · majorityWho each hero is; the natural home for a unique-name rule.
meadow_inventory1 · compact · majorityOne record per bag slot; a lost item is a support ticket.
meadow_gold, meadow_xp1 · delete, kept forever · keyed by entry · view sumsRewards never overwrite each other; balances by lookup.
meadow_ground_items1 · compact · tombstonesLoot appears and disappears; picked up inside a transaction.
character_location1 · compact · 3 copiesWhich server owns a hero; losing it strands the hero.
realm_servers, realm_ticketstransientHeartbeats and one-minute passes; worthless after a restart.

The syntax for every choice is on the QL page; the code that writes and reads them is in the API.