Skip to content
Writing a Client

Writing a Client

What a client of the protocol has to do, whatever its language. The calls themselves are in the HTTP API.

Reads

  • Tell a trailer apart from an event by its shape: a hasMore key for QUERY /events, an end key in a transaction.
  • Treat a response with no trailer as cut short. Outside a transaction, resume after the last full event. In a transaction, abandon it and run the command again.
  • Parse a read line by line. Each line has 30 seconds to go out: read at your own pace, but don’t stop.

Transactions

  • After a read of events, the next call is the write of events that closes it, with events or an empty list.
  • Read a projection in the transaction before you replace or delete it. A create needs no read.
  • Send one call at a time on a transaction.
  • After 409 ConcurrencyException or 404 TransactionNotFound, run the whole command again, in a new transaction.
  • POST /tx can get 503 Paused, or 503 TooManyTransactions. What to do with the command is the application’s choice.
  • 507 StorageFull means nothing was written, and the transaction is over. Don’t retry on your own: the disk stays full until the operator frees space.
  • Abandon a transaction you no longer need, for example in the error handler around a command, and ignore the response.
  • Give each event of a write the time the write returned: it’s the time the event keeps once committed.

Projections

  • Treat a version as opaque: compare it for equality only.
  • After POST /projections, use the version from the response for the next change.

Lost responses

  • A commit can’t be sent again. Run the command again, in a new transaction.
  • A POST /projections can be sent again as is. On a 409, read the projections again.

Testing

  • In development mode, empty the store between tests with DELETE /events, then DELETE /projections.
  • testdata/query-cases.json lists queries, events, and whether each query selects each event.

How the server works

How the server works inside, and the reasons behind its behavior, are in the Go comments of the repository. go doc ./... gives the role of each package.