Wire Protocol

Binary wire protocol reference for the Flo client-server communication.

Clients talk to Flo over TCP on the client port (default 9000) with a binary protocol: a fixed 32-byte header, then a payload. All integers are little-endian. The dashboard and metrics have their own HTTP ports.

Request

Header (32 bytes)

OffsetFieldTypeDescription
0magicu320x004F4C46 (the bytes F L O \0)
4payload_lengthu32Bytes of payload after the header
8request_idu64Chosen by the client; the response carries it back
16crc32u32CRC-32 of the header (this field excluded) and the payload
20op_codeu16The operation (see OpCodes)
22versionu80x03, the protocol version
23flagsu80: no flag is defined, and a request with any bit set is refused
24table_hashu64The hash of the op table the client was built for

Payload

[namespace_len:u16][namespace][key_len:u16][key][value_len:u32][value][options_len:u16][options]

An empty namespace is the default namespace for most operations. Options are a sequence of [tag:u8][len:u8][value] entries (see Options).

Table ops

Every KV op is declared in the op table. Their payload has no value length and no options; the body is the rest of the payload:

[namespace_len:u16][namespace][key_len:u16][key][body]

The body is the op's fields, in order. A field that may be left out is a presence byte (0 or 1) and then its value; a field with a default is sent present. Integers are fixed-width; bytes have a length prefix as wide as their bound needs (u8 up to 255, u16 up to 65535, else u32): a cursor a u8, a path a u16, a value or a document a u32. A list has a count prefix by the same rule, then its elements. An answer is the op's answer fields the same way, and must decode whole. A body that doesn't decode is refused bad_request with malformed, field_too_long or out_of_range, naming the field and the bound it broke, with ran = no.

OpRequest fieldsAnswer
kv_getwait_ms: u64 (default 0, at most 300000), wait_for: u8 (0 exists, the default; 1 change), txn?: u64version: u64, value: bytes, expires_at_ms?: i64, absent without a TTL
kv_putvalue: bytes (at most 257916), ttl_ms?: u64, condition: u8 (0 always, the default; 1 if_absent; 2 if_present), cas_version?: u64, txn?: u64version?: u64, absent inside a transaction
kv_deletecas_version?: u64, txn?: u64existed?: bool, absent inside a transaction
kv_scanlimit: u32 (1 to 1024), cursor: bytes (empty on the first page)names: [string], cursor?: bytes, absent on the last page; a page can hold fewer names than limit, even none, while more follow
kv_historylimit: u32 (1 to 65, default 10), before_version?: u64versions: [{version: u64, at_ms: i64, deleted: bool, value: bytes}], newest first, more: bool
kv_mgetkeys: [bytes] (1 to 256)entries: [{found: bool, version: u64, value: bytes}], next?: u16
kv_incrdelta: i64 (default 1), txn?: u64version?: u64, value?: i64, both absent inside a transaction
kv_expirettl_ms: u64 (0 clears the TTL), cas_version?: u64, txn?: u64nothing
kv_existstxn?: u64exists: bool, version: u64
kv_json_getpath: string (default $)version: u64, document: bytes
kv_json_setpath: string (default $), document: bytes (JSON text)version: u64
kv_json_delpath: string (default $)version?: u64, absent when the path was $, which deleted the key
kv_begin_txnnothingtxn: u64, pinned: u64
kv_commit_txntxn: u64commit_index: u64, ops: u16
kv_rollback_txntxn: u64nothing

The key is the envelope's key, except: kv_scan's is the prefix to list (empty for every key); kv_begin_txn's is the key whose {tag} the transaction pins, and may not be empty; kv_mget, kv_commit_txn and kv_rollback_txn take an empty key.

kv_scan pages across every shard: cursor is the previous page's, unchanged. kv_mget answers as many keys as fit one response; next, when present, is the index of the first key not answered, so the client asks again from there. Each key is read on the shard that owns it, and the server gathers the answers; an mget isn't one snapshot across shards. kv_history answers versions older than before_version when it's given; more says older kept versions follow, so the client asks again with before_version set to the last version it got. Deleting a missing key isn't an error: it answers existed false. kv_incr on a value that isn't an 8-byte counter, and the JSON ops on a value that isn't JSON, are refused bad_request with wrong_type.

wait_for exists answers at once if the key exists, else when it's written; change answers the key's next version. Either answers not found when the wait ends with the key absent, and change answers the value still there.

A key routes by its {tag}: the text between its first { and the next }, so {user:1}:name and {user:1}:visits live together. {} is a tag too, an empty one, so every key holding one routes together. A key with no } after its first {, or no {, routes by the whole key. Keys hash to one of 4096 slots, the same for every node and cluster, and each slot belongs to one shard. A request that names no key runs on shard 0.

A transaction is pinned to the {tag} of the key it begins with, or the whole key if it has none; pinned is that routing hash. Its id is [slot:u16][counter:u48]: a request carrying one runs on the shard that owns that slot, and on that shard's leader, reads included. An id no shard holds is refused not_found with no_such_transaction. kv_commit_txn and kv_rollback_txn route by the id in their body. Inside a transaction an op's key must route with the key it was begun with: give every key the same {tag}. Another is refused bad_request with keys_not_colocated, ran = no. kv_scan, kv_mget, kv_history and the JSON ops take no transaction.

List operations

stream_list, queue_list, ts_list, action_list, processing_list and workflow_list_definitions page across every shard. Their request value is:

[limit:u32][cursor]

limit 0, or anything over 1024, is a page of 1024. cursor is empty on the first page and otherwise the cursor the previous page returned, unchanged. Every list answer ends with:

[has_more:u8][cursor_len:u16][cursor]

worker_list is declared in the op table: its request is limit: u32 (1 to 1024, default 1024), cursor: bytes (the last id of the page before; empty to start) and action: bytes (only workers that run this action; empty for every worker). Its answer is workers: [{id, worker_type, status, current_load, max_concurrency, tasks_completed, tasks_failed, registered_at_ms, last_heartbeat_ms, machine_id?}] in id order, then cursor?: bytes, absent on the last page.

processing_remove is declared in the op table: its key is the job id, and its request and answer are empty. A running job is refused conflict with reason job_running; a job that doesn't exist, not_found.

workflow_list_runs takes the workflow's name as its key, or an empty key for every workflow's runs, and pages with its own request value:

[limit:u32][status_len:u16][status][cursor_len:u16][cursor][search_len:u16][search]

Every field is sent, an empty one with a length of 0. Runs come newest first. limit 0 is a page of 100, and anything over 1024 is a page of 1024. Each entry is [run_id_len:u16][run_id][workflow_len:u16][workflow][status_len:u16][status][created_at:i64], and the answer ends like the other lists. A page can hold fewer runs than limit while more follow, so keep paging until has_more is 0. Pages run newest first from the cursor, so runs started after a listing's first page don't appear in that listing. A malformed cursor is refused bad_request.

Paging is not a snapshot. A cursor resumes each shard by name or by position, so names created or deleted between pages can be listed twice or skipped.

The namespace ops are declared in the op table and run on shard 0. The namespace an op acts on is its key; the envelope's namespace is unused.

OpRequestAnswer
namespace_create—— ; conflict if the name exists
namespace_delete—always refused bad_request: not supported yet
namespace_listlimit: u32 (1 to 1024, default 1024), cursor: bytes (the last name of the page before; empty to start)names: [bytes] in name order, then cursor?: bytes, absent on the last page
namespace_info—created_at_ms: i64; no_namespace if there is none

namespace_ensure (0x016) is sent only between shards; from a client it is answered exactly as an unknown op.

Response

Header (32 bytes)

OffsetFieldTypeDescription
0magicu320x004F4C46
4data_lenu32Bytes of data after the header
8request_idu64The request's id
16crc32u32CRC-32 of the header (this field excluded) and the data
20versionu80x03
21statusu8See Status codes
22flagsu80x01 stale; no other bit is defined
23_padu80
24table_hashu64The hash of the op table the server was built for

stale is set on every answer a halted shard gives to a read, a not-found included: the read succeeded, from the state just before the entry the shard halted at. It isn't an error.

A response carries no opcode: the client knows which request it sent. Any status but ok is a refusal, and its data is a refusal body.

Versions

The table hash covers every op's request and answer layout and every log entry's. Until an op family is declared in the table, its hand-coded layouts are versioned by an epoch folded into the hash, which every change to one bumps. A server serves only clients carrying its own hash and protocol version; flo version --verbose prints both. This release is protocol version 3, table hash 0xc1f93eb0ed86a281.

A request from another build is answered bad_request in the client's own version byte, carrying the server's hash, with a message naming both builds, such as server table 0x…, client table 0x…: upgrade the client. Then the connection is closed. The server counts these in flo_client_version_refused_total. A client checks an answer's version and hash before reading its data, and refuses an answer from another build.

Nodes built from different tables can't link either: a peer's hello carries the hash. Upgrade by stopping every node, upgrading flo, the CLI and every SDK together, then starting every node.

Status codes

CodeName
0ok
1error_generic
2not_found
3bad_request
4cross_core_transaction
5no_active_transaction
6group_locked
7unauthorized
8conflict
9internal_error
10overloaded
11rate_limited
12unavailable
13outcome_pending
14no_namespace
15limit

no_namespace: the namespace a request names doesn't exist. It isn't not_found, which means a missing key.

limit: the node holds as much of something as the server is built to keep (reasons 32 to 35); it never ran. No setting raises these limits, so retrying won't help until something is deleted. Only too_many_actions is returned today: an action's shard holds 10,000 actions.

outcome_pending is a write that committed but hasn't applied, because its shard halted at it or before it (reason shard_halted, ran = unknown). The message says which: one past the halt applies when the shard resumes; the one it halted at never runs. Don't resend it unchanged: that writes it twice, or halts again.

Refusals

Every refusal's data is:

[reason:u16][ran:u8][message]

The status says whether to retry; the reason says what happened; ran says whether the request took effect, so retry logic reads a byte, not text; the message is for a person. A message too long for its frame is cut at a UTF-8 code point and ends …[truncated].

ranMeaning
0 noIt didn't take effect.
1 yesIt took effect: don't resend it.
2 unknownIt may still take effect: check before resending.
ReasonNameWhen
1unknown_opThe op code names no op this server serves.
2malformedThe frame or a field isn't what it declares.
3field_too_longA field or the request is longer than its bound.
4out_of_rangeA number is outside its range, such as a wait past 5 minutes.
5leader_unknownThe write found no leader, or a leader still applying earlier terms that refuses it; or the read found a node not yet caught up with what its group committed: such a leader, or a member restarting. Retry.
6shard_busyThe shard that owns the request is too busy to take it.
7table_mismatchThe client was built from another op table or protocol version.
8unknown_flagA header flag bit is set; none is defined.
9internalA server bug.
10committed_not_appliedThe write committed but this node didn't apply it (ran = yes).
11answer_lostIts answer couldn't be built or sent. A committed write's lost answer has ran = yes; an answer too large to frame has ran = unknown.
12unclassifiedFrom an op family not yet classified; the status and message say what happened.
13not_foundWhat the request names doesn't exist.
14reserved_keyThe key is in a prefix the server keeps for itself.
15cas_mismatchThe write's cas_version isn't the key's version.
16condition_failedThe write's condition didn't hold.
17no_such_transactionNo open transaction has this id here: it committed, rolled back, was begun in another namespace, or never existed.
18keys_not_colocatedThe key routes elsewhere than the key the transaction was begun with: give every key in a transaction the same {tag}.
19txn_too_largeThe transaction holds as many ops or bytes as it may.
20too_many_waitersThe shard holds as many waiting reads as it may.
21conflicting_fieldsTwo fields given together that don't go together, such as a wait inside a transaction.
22writes_stoppedThe shard stopped taking writes: one left memory before it reached disk. It takes them again once the node restarts.
23too_many_proposalsToo many writes wait for commit.
24wrong_typeThe key's value isn't what the op works on: a counter for kv_incr, JSON for the JSON ops.
25too_many_transactionsThe shard holds as many open transactions as it may.
26stale_reportAn action complete or fail for a run that has moved on: another worker holds it, or it finished with another outcome. The report was dropped; resending it is refused the same way.
27worker_unhealthyThe worker missed its heartbeats and gets no work until it sends one or registers again.
28worker_drainingThe worker is draining and gets no new work.
29shard_haltedThe shard halted at an entry every replica fails the same way. With unavailable (ran = no) it takes no writes until the entry is repaired, so retrying doesn't help; with outcome_pending, see above.
30admin_onlyThe op is served only on the node's admin socket.
31job_runningThe processing job is running: stop or cancel it, then remove it.
32memory_budgetWith limit: the node's memory budget is spent. Not returned yet.
33too_many_actionsWith limit: the action's shard holds 10,000 actions; delete one to register another.
34too_many_workflow_definitionsWith limit: the node holds as many workflow definitions as it keeps. Not returned yet.
35too_many_workflow_runsWith limit: the node holds as many workflow runs as it keeps. Not returned yet.
36queue_fullWith overloaded: an enqueue found the queue at its cap of messages or bytes, or the shard's queues and groups together at theirs. It drains as messages are completed; the SDKs retry it with backoff.
37group_held_fullWith overloaded: a group read took nothing new, because the group holds as many records or bytes as its caps allow (the [queues] settings, which hold each group as they hold a queue), or the shard's queues and groups together hold theirs. The SDKs don't retry it: reading again won't help. A group's cap counts its leased, ready and dead records; an ack frees a record, but dead ones leave only when the group is deleted or a stream trim passes them. The shard's cap clears as its queues and groups drain.

The reasons are part of the op table, so a client and server that agree on the table hash agree on this list.

OpCodes

The protocol defines 101 operation codes, grouped by subsystem.

System (0x000 – 0x00F)

OpCodeValue
ping0x000
system_walk_page0x001 (between shards only)
system_runs_page0x002 (between shards only)
system_holds_run0x003 (between shards only)

Namespace (0x010 – 0x02F)

OpCodeValue
namespace_create0x010
namespace_delete0x011
namespace_list0x012
namespace_info0x013
namespace_ensure0x016 (between shards only)
namespace_published0x017 (between shards only)

Cluster (0x030 – 0x04F)

OpCodeValue
cluster_status0x030
cluster_members0x031
cluster_promote0x032
cluster_remove0x033
cluster_repair_skip0x034 (admin socket only)

A cluster_promote value is the node id, u32 little-endian (4 bytes). A cluster_remove value is the node id, u32 little-endian, then one byte that is non-zero to allow a removal that leaves an even number of voters (5 bytes). Any other length is refused with bad_request. Both are answered with an empty value once the change commits; promoting a node that is already a voter is answered at once.

KV + Transactions + Snapshots (0x100 – 0x12F)

OpCodeValue
kv_put0x100
kv_get0x101
kv_mget0x102
kv_delete0x103
kv_scan0x104
kv_history0x105

KV Extended (atomic counters, JSON ops)

OpCodeValue
kv_incr0x10B
kv_json_get0x10C
kv_json_set0x10D
kv_json_del0x10E

KV Per-Shard Transactions

OpCodeValue
kv_begin_txn0x110
kv_commit_txn0x111
kv_rollback_txn0x112

KV Extended (TTL lifecycle, exists)

OpCodeValue
kv_expire0x113
kv_exists0x115

Streams (0x130 – 0x14F)

OpCodeValue
stream_append0x130
stream_read0x131
stream_trim0x132
stream_info0x133
stream_list0x13B
stream_create0x13D
stream_alter0x13F
stream_delete0x140

Stream Consumer Groups (0x150 – 0x16F)

OpCodeValue
stream_group_create0x150
stream_group_join0x151 (removed: refused)
stream_group_leave0x152 (removed: refused)
stream_group_read0x153
stream_group_ack0x154
stream_group_claim0x155 (removed: refused)
stream_group_pending0x156
stream_group_configure_sweeper0x157 (removed: refused)
stream_group_nack0x159
stream_group_touch0x15A
stream_group_info0x15B
stream_group_delete0x15C
stream_group_list0x15D
stream_group_members0x15E

The removed ops are refused bad_request, naming what replaces them.

An ack, nack or touch names a read's delivery and its records: [group_len:u16][group][consumer_len:u16][consumer][term:u64][index:u64][count:u32]([ms:u64][seq:u64][deliveries:u32])*. A nack then carries its error, [error_len:u16][error], at most 1024 bytes, 0 for none; options delay_ms, dead or abandon say what becomes of the records. abandon hands them back unstarted: ready at once, the delivery counted but no failure. It is refused with dead, delay_ms or an error. An abandoned record never dead-letters, so abandon only records a consumer didn't start, or that its stop cut short; nack a record that failed, or a poison record goes round for ever. A report to a group that doesn't exist is refused not_found.

Queues (0x170 – 0x19F)

OpCodeValue
queue_enqueue0x170
queue_dlq_list0x176
queue_dlq_delete0x177
queue_dlq_requeue0x178
queue_stats0x17B
queue_purge0x17F
queue_peek0x180
queue_dequeue0x181
queue_complete0x182
queue_fail0x183
queue_touch0x184
queue_list0x198

A queue_dlq_list value is [limit:u32][after_seq:u64], both optional: up to limit dead letters (1 to 100; 100 when absent) after the one whose seq is after_seq (from the oldest when absent). The answer is [count:u32]([seq:u64][size:u32][len:u32][payload][enqueued_at_ms:i64][deliveries:u32][priority:u8][moved_at_ms:i64])*[total:u64][has_more:u8][last_seq:u64], oldest first; payload is at most 4 KiB of the message's size bytes. To read the next page, send the answer's last_seq as after_seq.

Time-Series (0x1A0 – 0x1BF)

OpCodeValue
ts_write0x1A0
ts_read0x1A1
ts_query0x1A2
ts_floql0x1A3
ts_list0x1A4
ts_delete0x1A5
ts_retention0x1A6
ts_info0x1A7

A ts_write value is exactly one finite f64, 8 bytes little-endian; any other length, NaN or infinity is refused with bad_request.

Actions (0x300 – 0x31F)

OpCodeValue
action_register0x300
action_invoke0x301
action_status0x302
action_list0x303
action_list_runs0x304
action_delete0x305
action_await0x30A
action_complete0x30B
action_fail0x30C
action_touch0x30D
action_deliver0x30E (between shards only)
action_info0x30F

action_list_runs takes the action's name as its key: an action's runs live on its name's shard. An empty key is refused bad_request, action name is required.

An action_invoke value is [has_labels:u8]([labels_len:u16][labels])?[input]: has_labels is 0 and the input follows, or 1 and the required worker labels, a JSON object, come first. An empty value, has_labels other than 0 or 1, labels that run past the value, or labels that aren't a JSON object are refused with bad_request.

Workers (0x320 – 0x33F)

OpCodeValue
worker_register0x320
worker_heartbeat0x321
worker_deregister0x322
worker_list0x323
worker_info0x324
worker_drain0x325

Workflows (0x340 – 0x35F)

OpCodeValue
workflow_create0x340
workflow_start0x341
workflow_signal0x342
workflow_cancel0x343
workflow_status0x344
workflow_history0x345
workflow_list_runs0x346
workflow_get_definition0x347
workflow_disable0x348
workflow_enable0x349
workflow_list_definitions0x34A

Processing (0x360 – 0x37F)

OpCodeValue
processing_submit0x360
processing_stop0x361
processing_cancel0x362
processing_status0x363
processing_list0x364
processing_remove0x365

Options

Tags the server reads. An option it doesn't recognise is ignored for now; that changes with the typed op table.

TagNameValue
0x05limitu32: Maximum results for ts_read (earliest first); absent or 0 is all. List operations take theirs in the value
0x10priorityu8: Message priority (0-255; lower is taken first)
0x11delay_msu64: How long before a message, or a nacked group record, is ready (at most a day)
0x15countu32: Number of messages to dequeue
0x17block_msu32: Long-poll wait (at most 5 min; 0 = don't wait); a longer one is refused
0x21stream_start[16]u8: Read records after this StreamID (exclusive)
0x22stream_end[16]u8: End StreamID for reads (inclusive)
0x23stream_tailvoid: Flag indicating tail read (start from end of stream)
0x24partitionu32: Explicit partition index
0x25partition_keystring: Key for partition routing
0x26max_age_secondsu64: Trim records older than this many seconds
0x27max_bytesRefused: byte-based trim isn't supported (#183)
0x28dry_runvoid: Trim answers what it would remove and removes nothing
0x29retention_countu64: Retention policy - max event count
0x2Aretention_ageu64: Retention policy - max age in seconds
0x2Bretention_bytesRefused: byte retention isn't supported (#183)
0x2Cforcevoid: Force a destructive op (e.g. delete a non-empty stream)
0x30ack_timeout_msu32: A group's lease: a record not acked this long is delivered again (5 s to 12 h; default 30 s)
0x31max_deliveru8: A group's attempts: a record is dead once nacked or expired this many times (1 to 255; default 5)
0x32deadvoid: A nack makes its records dead now
0x34abandonvoid: A nack hands its records back unstarted: ready at once, no failure counted
0x60ts_from_msi64: Start of time range (inclusive, unix ms)
0x61ts_to_msi64: End of time range (inclusive, 0 = now)
0x62ts_window_msi64: Aggregation window size (ms)
0x63ts_aggregationstring: Aggregation function name (avg, sum, count, min, max)
0x64ts_fieldstring: Field name filter (empty = "value")
0x65ts_tagsstring: Comma-separated tag filters "key=val,key2=val2"
0x67ts_timestampi64: A write's timestamp in ms; absent, 0 or less = the server's clock
0x68ts_raw_ttlstring: Raw data TTL (e.g., "7d")
0x69ts_downsamplestring: refused — downsampling isn't supported (#158)