Skip to main content
Appends support two mechanisms for concurrency control:

Match sequence number

Specifying expected current state allows optimistic concurrency control. You can provide the sequence number that you expect S2 to assign to the first record in a batch as the match_seq_num. If it does not match, this will result in a 412 Precondition Failed status or corresponding SDK error type.
To achieve “exactly-once” semantics in single-writer setups, match_seq_num can be used when appending. See append retry policy in the SDK docs.

Fencing tokens

Fencing is a form of pessimistic concurrency control. It is a cooperative mechanism, so an append that does not specify a fencing token will still be allowed. When an append does include a fencing_token and it does not match, this results in a 412 Precondition Failed status or corresponding SDK error type.

Setting a fencing token

Set a fencing token via the CLI:
s2 fence s2://my-basin/my-stream "writer-1"
Subsequent appends that specify a token will be rejected if it doesn’t match:
s2 append s2://my-basin/my-stream -f "writer-1"
Fencing tokens can be up to 36 UTF-8 bytes. An empty token clears the fence. Fencing is strongly consistent — once set, subsequent appends specifying a different token are immediately rejected.
Fencing is also available via the SDKs and REST API.

See also