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)
| Offset | Field | Type | Description |
|---|---|---|---|
| 0 | magic | u32 | 0x004F4C46 (the bytes F L O \0) |
| 4 | payload_length | u32 | Bytes of payload after the header |
| 8 | request_id | u64 | Chosen by the client; the response carries it back |
| 16 | crc32 | u32 | CRC-32 of the header (this field excluded) and the payload |
| 20 | op_code | u16 | The operation (see OpCodes) |
| 22 | version | u8 | 0x03, the protocol version |
| 23 | flags | u8 | 0: no flag is defined, and a request with any bit set is refused |
| 24 | table_hash | u64 | The 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.
| Op | Request fields | Answer |
|---|---|---|
kv_get | wait_ms: u64 (default 0, at most 300000), wait_for: u8 (0 exists, the default; 1 change), txn?: u64 | version: u64, value: bytes, expires_at_ms?: i64, absent without a TTL |
kv_put | value: bytes (at most 257916), ttl_ms?: u64, condition: u8 (0 always, the default; 1 if_absent; 2 if_present), cas_version?: u64, txn?: u64 | version?: u64, absent inside a transaction |
kv_delete | cas_version?: u64, txn?: u64 | existed?: bool, absent inside a transaction |
kv_scan | limit: 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_history | limit: u32 (1 to 65, default 10), before_version?: u64 | versions: [{version: u64, at_ms: i64, deleted: bool, value: bytes}], newest first, more: bool |
kv_mget | keys: [bytes] (1 to 256) | entries: [{found: bool, version: u64, value: bytes}], next?: u16 |
kv_incr | delta: i64 (default 1), txn?: u64 | version?: u64, value?: i64, both absent inside a transaction |
kv_expire | ttl_ms: u64 (0 clears the TTL), cas_version?: u64, txn?: u64 | nothing |
kv_exists | txn?: u64 | exists: bool, version: u64 |
kv_json_get | path: string (default $) | version: u64, document: bytes |
kv_json_set | path: string (default $), document: bytes (JSON text) | version: u64 |
kv_json_del | path: string (default $) | version?: u64, absent when the path was $, which deleted the key |
kv_begin_txn | nothing | txn: u64, pinned: u64 |
kv_commit_txn | txn: u64 | commit_index: u64, ops: u16 |
kv_rollback_txn | txn: u64 | nothing |
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.
| Op | Request | Answer |
|---|---|---|
namespace_create | — | — ; conflict if the name exists |
namespace_delete | — | always refused bad_request: not supported yet |
namespace_list | limit: 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)
| Offset | Field | Type | Description |
|---|---|---|---|
| 0 | magic | u32 | 0x004F4C46 |
| 4 | data_len | u32 | Bytes of data after the header |
| 8 | request_id | u64 | The request's id |
| 16 | crc32 | u32 | CRC-32 of the header (this field excluded) and the data |
| 20 | version | u8 | 0x03 |
| 21 | status | u8 | See Status codes |
| 22 | flags | u8 | 0x01 stale; no other bit is defined |
| 23 | _pad | u8 | 0 |
| 24 | table_hash | u64 | The 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
| Code | Name |
|---|---|
0 | ok |
1 | error_generic |
2 | not_found |
3 | bad_request |
4 | cross_core_transaction |
5 | no_active_transaction |
6 | group_locked |
7 | unauthorized |
8 | conflict |
9 | internal_error |
10 | overloaded |
11 | rate_limited |
12 | unavailable |
13 | outcome_pending |
14 | no_namespace |
15 | limit |
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].
ran | Meaning |
|---|---|
0 no | It didn't take effect. |
1 yes | It took effect: don't resend it. |
2 unknown | It may still take effect: check before resending. |
| Reason | Name | When |
|---|---|---|
1 | unknown_op | The op code names no op this server serves. |
2 | malformed | The frame or a field isn't what it declares. |
3 | field_too_long | A field or the request is longer than its bound. |
4 | out_of_range | A number is outside its range, such as a wait past 5 minutes. |
5 | leader_unknown | The 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. |
6 | shard_busy | The shard that owns the request is too busy to take it. |
7 | table_mismatch | The client was built from another op table or protocol version. |
8 | unknown_flag | A header flag bit is set; none is defined. |
9 | internal | A server bug. |
10 | committed_not_applied | The write committed but this node didn't apply it (ran = yes). |
11 | answer_lost | Its 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. |
12 | unclassified | From an op family not yet classified; the status and message say what happened. |
13 | not_found | What the request names doesn't exist. |
14 | reserved_key | The key is in a prefix the server keeps for itself. |
15 | cas_mismatch | The write's cas_version isn't the key's version. |
16 | condition_failed | The write's condition didn't hold. |
17 | no_such_transaction | No open transaction has this id here: it committed, rolled back, was begun in another namespace, or never existed. |
18 | keys_not_colocated | The key routes elsewhere than the key the transaction was begun with: give every key in a transaction the same {tag}. |
19 | txn_too_large | The transaction holds as many ops or bytes as it may. |
20 | too_many_waiters | The shard holds as many waiting reads as it may. |
21 | conflicting_fields | Two fields given together that don't go together, such as a wait inside a transaction. |
22 | writes_stopped | The shard stopped taking writes: one left memory before it reached disk. It takes them again once the node restarts. |
23 | too_many_proposals | Too many writes wait for commit. |
24 | wrong_type | The key's value isn't what the op works on: a counter for kv_incr, JSON for the JSON ops. |
25 | too_many_transactions | The shard holds as many open transactions as it may. |
26 | stale_report | An 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. |
27 | worker_unhealthy | The worker missed its heartbeats and gets no work until it sends one or registers again. |
28 | worker_draining | The worker is draining and gets no new work. |
29 | shard_halted | The 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. |
30 | admin_only | The op is served only on the node's admin socket. |
31 | job_running | The processing job is running: stop or cancel it, then remove it. |
32 | memory_budget | With limit: the node's memory budget is spent. Not returned yet. |
33 | too_many_actions | With limit: the action's shard holds 10,000 actions; delete one to register another. |
34 | too_many_workflow_definitions | With limit: the node holds as many workflow definitions as it keeps. Not returned yet. |
35 | too_many_workflow_runs | With limit: the node holds as many workflow runs as it keeps. Not returned yet. |
36 | queue_full | With 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. |
37 | group_held_full | With 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)
| OpCode | Value |
|---|---|
ping | 0x000 |
system_walk_page | 0x001 (between shards only) |
system_runs_page | 0x002 (between shards only) |
system_holds_run | 0x003 (between shards only) |
Namespace (0x010 – 0x02F)
| OpCode | Value |
|---|---|
namespace_create | 0x010 |
namespace_delete | 0x011 |
namespace_list | 0x012 |
namespace_info | 0x013 |
namespace_ensure | 0x016 (between shards only) |
namespace_published | 0x017 (between shards only) |
Cluster (0x030 – 0x04F)
| OpCode | Value |
|---|---|
cluster_status | 0x030 |
cluster_members | 0x031 |
cluster_promote | 0x032 |
cluster_remove | 0x033 |
cluster_repair_skip | 0x034 (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)
| OpCode | Value |
|---|---|
kv_put | 0x100 |
kv_get | 0x101 |
kv_mget | 0x102 |
kv_delete | 0x103 |
kv_scan | 0x104 |
kv_history | 0x105 |
KV Extended (atomic counters, JSON ops)
| OpCode | Value |
|---|---|
kv_incr | 0x10B |
kv_json_get | 0x10C |
kv_json_set | 0x10D |
kv_json_del | 0x10E |
KV Per-Shard Transactions
| OpCode | Value |
|---|---|
kv_begin_txn | 0x110 |
kv_commit_txn | 0x111 |
kv_rollback_txn | 0x112 |
KV Extended (TTL lifecycle, exists)
| OpCode | Value |
|---|---|
kv_expire | 0x113 |
kv_exists | 0x115 |
Streams (0x130 – 0x14F)
| OpCode | Value |
|---|---|
stream_append | 0x130 |
stream_read | 0x131 |
stream_trim | 0x132 |
stream_info | 0x133 |
stream_list | 0x13B |
stream_create | 0x13D |
stream_alter | 0x13F |
stream_delete | 0x140 |
Stream Consumer Groups (0x150 – 0x16F)
| OpCode | Value |
|---|---|
stream_group_create | 0x150 |
stream_group_join | 0x151 (removed: refused) |
stream_group_leave | 0x152 (removed: refused) |
stream_group_read | 0x153 |
stream_group_ack | 0x154 |
stream_group_claim | 0x155 (removed: refused) |
stream_group_pending | 0x156 |
stream_group_configure_sweeper | 0x157 (removed: refused) |
stream_group_nack | 0x159 |
stream_group_touch | 0x15A |
stream_group_info | 0x15B |
stream_group_delete | 0x15C |
stream_group_list | 0x15D |
stream_group_members | 0x15E |
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)
| OpCode | Value |
|---|---|
queue_enqueue | 0x170 |
queue_dlq_list | 0x176 |
queue_dlq_delete | 0x177 |
queue_dlq_requeue | 0x178 |
queue_stats | 0x17B |
queue_purge | 0x17F |
queue_peek | 0x180 |
queue_dequeue | 0x181 |
queue_complete | 0x182 |
queue_fail | 0x183 |
queue_touch | 0x184 |
queue_list | 0x198 |
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)
| OpCode | Value |
|---|---|
ts_write | 0x1A0 |
ts_read | 0x1A1 |
ts_query | 0x1A2 |
ts_floql | 0x1A3 |
ts_list | 0x1A4 |
ts_delete | 0x1A5 |
ts_retention | 0x1A6 |
ts_info | 0x1A7 |
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)
| OpCode | Value |
|---|---|
action_register | 0x300 |
action_invoke | 0x301 |
action_status | 0x302 |
action_list | 0x303 |
action_list_runs | 0x304 |
action_delete | 0x305 |
action_await | 0x30A |
action_complete | 0x30B |
action_fail | 0x30C |
action_touch | 0x30D |
action_deliver | 0x30E (between shards only) |
action_info | 0x30F |
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)
| OpCode | Value |
|---|---|
worker_register | 0x320 |
worker_heartbeat | 0x321 |
worker_deregister | 0x322 |
worker_list | 0x323 |
worker_info | 0x324 |
worker_drain | 0x325 |
Workflows (0x340 – 0x35F)
| OpCode | Value |
|---|---|
workflow_create | 0x340 |
workflow_start | 0x341 |
workflow_signal | 0x342 |
workflow_cancel | 0x343 |
workflow_status | 0x344 |
workflow_history | 0x345 |
workflow_list_runs | 0x346 |
workflow_get_definition | 0x347 |
workflow_disable | 0x348 |
workflow_enable | 0x349 |
workflow_list_definitions | 0x34A |
Processing (0x360 – 0x37F)
| OpCode | Value |
|---|---|
processing_submit | 0x360 |
processing_stop | 0x361 |
processing_cancel | 0x362 |
processing_status | 0x363 |
processing_list | 0x364 |
processing_remove | 0x365 |
Options
Tags the server reads. An option it doesn't recognise is ignored for now; that changes with the typed op table.
| Tag | Name | Value |
|---|---|---|
0x05 | limit | u32: Maximum results for ts_read (earliest first); absent or 0 is all. List operations take theirs in the value |
0x10 | priority | u8: Message priority (0-255; lower is taken first) |
0x11 | delay_ms | u64: How long before a message, or a nacked group record, is ready (at most a day) |
0x15 | count | u32: Number of messages to dequeue |
0x17 | block_ms | u32: Long-poll wait (at most 5 min; 0 = don't wait); a longer one is refused |
0x21 | stream_start | [16]u8: Read records after this StreamID (exclusive) |
0x22 | stream_end | [16]u8: End StreamID for reads (inclusive) |
0x23 | stream_tail | void: Flag indicating tail read (start from end of stream) |
0x24 | partition | u32: Explicit partition index |
0x25 | partition_key | string: Key for partition routing |
0x26 | max_age_seconds | u64: Trim records older than this many seconds |
0x27 | max_bytes | Refused: byte-based trim isn't supported (#183) |
0x28 | dry_run | void: Trim answers what it would remove and removes nothing |
0x29 | retention_count | u64: Retention policy - max event count |
0x2A | retention_age | u64: Retention policy - max age in seconds |
0x2B | retention_bytes | Refused: byte retention isn't supported (#183) |
0x2C | force | void: Force a destructive op (e.g. delete a non-empty stream) |
0x30 | ack_timeout_ms | u32: A group's lease: a record not acked this long is delivered again (5 s to 12 h; default 30 s) |
0x31 | max_deliver | u8: A group's attempts: a record is dead once nacked or expired this many times (1 to 255; default 5) |
0x32 | dead | void: A nack makes its records dead now |
0x34 | abandon | void: A nack hands its records back unstarted: ready at once, no failure counted |
0x60 | ts_from_ms | i64: Start of time range (inclusive, unix ms) |
0x61 | ts_to_ms | i64: End of time range (inclusive, 0 = now) |
0x62 | ts_window_ms | i64: Aggregation window size (ms) |
0x63 | ts_aggregation | string: Aggregation function name (avg, sum, count, min, max) |
0x64 | ts_field | string: Field name filter (empty = "value") |
0x65 | ts_tags | string: Comma-separated tag filters "key=val,key2=val2" |
0x67 | ts_timestamp | i64: A write's timestamp in ms; absent, 0 or less = the server's clock |
0x68 | ts_raw_ttl | string: Raw data TTL (e.g., "7d") |
0x69 | ts_downsample | string: refused — downsampling isn't supported (#158) |