Skip to content

Operations

This page lists what a program can ask rulfo to do. Only request is designed in detail. The bytes are in Wire format.

request

A requester sends one request to a key. Every replier that handles the key sends zero, one or many replies, then an end. The requester gets exactly one outcome, unless it stops waiting (rule 15).

Outcome When
completed Every replier sent its end, no replier refused, and every reply that was sent arrived. The number of replies can be zero.
busy Every replier sent its end, and at least one refused the request. A replier that refused did not run it.
expired The deadline passed first. The request may have run. Replies that arrived before the deadline were delivered.
unroutable No replier handles the key. Nothing ran. The requester learns this at once, unless the connection drops first: then the outcome can be expired.

With one replier, busy means that nothing ran. With more than one, another replier may have run the request.

Rules:

  1. A request has a deadline: a time on the requester's clock. There is no request without one.
  2. A request has an id, chosen by the requester. 16 bytes. A replier runs one id at most once.
  3. A reply carries the id of its request and its number, from 0. The requester drops a reply for an unknown or ended id. From one replier it takes only the next number: it drops a number it already has, and a higher one.
  4. A replier is not required to reply. It is required to end. A replier that never ends is covered by the deadline.
  5. An end carries the number of replies the replier sent. The requester accepts the end only when it received that many. Otherwise the outcome is expired at the deadline.
  6. After a reconnect, the requester sends an open request again, with the same id and the same deadline, marked as sent again. It does this only for a replier that drops repeated ids.
  7. A replier keeps the id of a request it runs until the deadline plus the keep time (a setting, 60 s by default). It never forgets the id earlier, never while the handler runs, and never to make room for another id.
  8. A replier drops a copy that it reads after the deadline.
  9. A replier looks up the id first, and never runs a copy with a known id. If such a copy is marked as sent again, the replier may send its replies again. Otherwise it answers nothing.
  10. A replier refuses a new request that it cannot accept: its store of ids is full, or the deadline is longer than the replier accepts (a setting). It sends an end marked busy and does not run the handler. A replier that does not drop repeated ids has no store, so only the deadline applies. A replier refuses before its first reply.
  11. A replier runs or drops a copy marked as sent again. It never answers it with busy or with "no handler", because an older copy on the closed connection can still be read and run. It refuses another copy only while the connection that brought it is open. If that connection ended first, the replier sends nothing and forgets the id: it did not run the request.
  12. One connection has at most one copy of a request that has no end. The requester sends a new copy after a busy end, or on a new connection. After it sends on a new connection, it reads nothing from the old one.
  13. A requester may send a refused request again, with the same id and the same deadline, when every replier refused it. When only some refused, a retry cannot complete: a replier that already ran the request drops the repeat and sends no end.
  14. Every process that sends a copy of one request reads the same clock. Two senders may differ by at most the keep time minus the handshake limit: 55 s with the defaults. The clock does not jump. One process with its own monotonic clock meets this rule. Several processes (several API replicas, or a restart that keeps open requests) need a clock they share.
  15. A requester may stop waiting for a request. It gets no outcome and no more replies, and it does not send that id again. Nothing goes on the wire, so the replier may run the request to its end.
  16. A requester that sends a copy, when another copy may already have been sent, marks it as sent again. Without a connection it waits for one until the deadline: unroutable would say that nothing ran.

Replies lost in a reconnect

A replier that gets a known id, marked as sent again, tells its program the number of replies sent and whether the end was sent. The program stores the replies: the C core does not. The Python package stores them, up to a limit.

The program chooses one of two:

  • Send the replies again: all of them, from number 0, in order, up to the newest one. Then send the end again, if it was sent. A new reply that was sent before this is dropped by the requester, and is part of what is sent again.
  • Send nothing. If a reply or the end was lost, the outcome is expired.

The program keeps stored replies no longer than the replier keeps the id. It may keep fewer, for example under a size limit.

A reply that arrives twice reaches the caller once (rule 3). The count in the end stays correct (rule 5). A refused request has no stored id, so nothing is sent again for it.

Clocks

A replier reads a deadline on its own clock. It uses the clock value that the requester sends once on each connection (see Wire format). A copy gets the same deadline however long it waits in a buffer.

That deadline is late by at most the handshake limit. The keep time is longer than the limit, so a replier still has the id when it reads a copy that is not past its deadline.

Limits:

  • rulfo does not check rule 14. Senders that differ by more can make a request run twice.
  • With senders that differ, a replier can drop a copy shortly before the real deadline. The copy does not run, and the outcome is expired.
  • A replier that restarts forgets its ids, and can run a copy again. The requester can then get replies of both runs in one completed outcome. Storing ids on disk is not designed yet.
  • Every copy of an id must reach the store that holds it. In the C core that is one rf_peer for one remote party, also when that party has several processes.

What a replier that crashed looks like to the requester: no end arrives, and the outcome is expired.

Planned and not planned

Only request is built. The other rows have no frames, rules or model yet. A rule is written and checked in a model before its code.

Need Covered by What it states
Request and reply, a query, a batch with an acknowledgement request, built One of the four outcomes.
The newest value of a key, state pushed to many parties latest, planned next A subscriber that stays connected ends with the newest version of each key. Versions never go back. Values in between can be skipped. Memory is one value for each key.
Learn that the other side is gone a link check (PING) and values tied to a connection, planned "Gone" is reported only after the connection ended, or stayed silent for longer than a limit.
A task for one of several workers (PUSH/PULL) work, waits for a program that needs it A task is offered until it is acknowledged, so it can run twice.

The shape that latest and the link check keep:

  • One wire protocol. Each addition has its own capability bit.
  • One connection between two parties. The side that accepts connections holds the values: there is no broker and no second hop.
  • A slow subscriber gets fewer values in between. There is no queue for each subscriber.

Not built

  • Publish and subscribe for events with no stored value. The only promise would be that an event can be lost.
  • Brokers, proxies, routing between machines and wildcard keys.
  • Compatibility with ZeroMQ or Zenoh.

Out of scope

  • Discovery. The address of the peer is given.
  • Encryption. The transport does it (socket permissions, TLS).
  • Storage. The host program saves and loads. The core only says what to save.