Skip to content

gRPC API

You can interact with an UmaDB server using its gRPC API.

The sections below detail the umadb.v1.DCB service defined in umadb.proto.

DCB Service

UmaDB's gRPC service for reading and appending events exposes four RPC methods:

NameRequestResponseDescription
AppendAppendRequestAppendResponseAppends new events atomically, with optional append condition, and optional tracking information.
ReadReadRequeststream ReadResponseStreams stored events from the server to the client, optionally as a subscription.
HeadHeadRequestHeadResponseReturns the position of the last event in the database; used to measure the volume of stored events.
GetTrackingInfoTrackingRequestTrackingResponseReturns the last recorded position in an upstream sequence of events; used when starting or resuming event processing components.

Append Request

Send an AppendRequest to the Append RPC to store new events. All the Event messages in the events field will be appended atomically in order, unless the AppendCondition given in the condition field fails.

FieldTypeDescription
eventsrepeated EventEvents to append, in order.
conditionoptional AppendConditionOptional condition to enforce optimistic concurrency and detect conflicts.
tracking_infooptional TrackingInfoOptional tracking information; used by event processing components to checkpoint their progress.

The server will return an AppendResponse message if the condition does not fail.

If the append condition fails, or if the tracking information conflicts, the server will return a gRPC error response with gRPC status FAILED_PRECONDITION and a human-readable message string. In addition, the gRPC status details attribute will have a serialised ErrorResponse message, that has the same human-readable message string and INTEGRITY as the error_type.

Conditional appending of events with UUIDs is idempotent. The server does not enforce uniqueness of event IDs.

Append Response

The server returns an AppendResponse message for each successful AppendRequest.

FieldTypeDescription
positionuint64Sequence number of the last appended event.

Clients can use the returned position to wait until downstream event processing components have become up-to-date, avoiding out-of-date views being presented to users.

Read Request

Send a ReadRequest to the Read RPC to read events from the event store.

Set query to select only specific events. Set start to read only from a specific position. If start is not set, events will be read from the first recorded event, or the last if backwards is true.

FieldTypeDescription
queryoptional QueryOptional filter for selecting specific event types or tags.
startoptional uint64Read from this sequence number.
backwardsoptional boolStart reading backwards (default false).
limitoptional uint32Maximum number of events to return (default unlimited).
subscribeoptional boolIf true, the stream remains open and continues delivering new events.
batch_sizeoptional uint32Optional batch size hint for streaming responses.

The server will return a stream of ReadResponse messages. The default value of subscribe is false, meaning the stream will end when all selected events have been received. When subscribe is true, the stream will continue as new events are appended to the store.

Read Response

A stream of ReadResponse messages are sent in response to each ReadRequest. A collection of SequencedEvent messages can be obtained from the events field.

FieldTypeDescription
eventsrepeated SequencedEventA batch of events matching the ReadRequest.query.
headoptional uint64The position of the last recorded event.

When ReadRequest.subscribe was false and ReadRequest.limit was None, the value of head will be the position of the last recorded event in the database during the reader transaction.

Otherwise, if ReadRequest.subscribe was true, the value of head will be empty.

Otherwise, if ReadRequest.limit was a uint64, the value of head will be the position of the last event in the message's events field.

Head Request

Send a HeadRequest to the Head RPC to get the position of the last recorded event in the event store.

This message has no fields.

Head Response

The server returns a HeadResponse message in response to each HeadRequest message sent by clients to the Head RPC.

FieldTypeDescription
positionoptional uint64The latest known event position, or None if the store is empty.

The position field contains the sequence position of the last recorded event in the store, or None if the store is empty.

Tracking Request

Send a TrackingRequest to the GetTrackingInfo RPC to get the last recorded position in an upstream sequence of events.

FieldTypeDescription
sourcestringUpstream sequence name.

Tracking Response

The server returns a TrackingResponse message in response to each TrackingRequest message sent by clients to the GetTrackingInfo RPC.

FieldTypeDescription
positionoptional uint64The last recorded position.

The position field contains the last recorded position in an upstream sequence of events, or None if the sequence name is not found.

Event

An Event represents a single event either to be appended or already stored in the event log.

FieldTypeDescription
event_typestringThe event’s logical type (e.g. "UserRegistered").
tagsrepeated stringTags assigned to the event (used for filtering and indexing).
databytesBinary payload associated with the event.
uuidstringUnique event ID (e.g. serialized version 4 UUIDv4).

Idempotent support for append operations is activated by setting a UUID on appended events. The server does not enforce uniqueness of event IDs.

Include in:

Included in:

Matched by:

Append Condition

An AppendCondition causes an append request to fail if events match its Query, optionally after a sequence number.

FieldTypeDescription
fail_if_events_matchoptional QueryQuery for conflicting events.
afteroptional uint64Sequence number.

Include in:

To implement a consistency boundary, command handlers can use the same Query used in ReadRequest as the value of fail_if_events_match, and the "head" received in the ReadResponse as the value of after, when appending new events generated by a decision model.

Tracking Info

A TrackingInfo message represents the source and position of an upstream event.

FieldTypeDescription
sourcestringUpstream sequence name.
positionuint64Upstream sequence number.

Include in:

  • AppendRequest when recording the results of processing an upstream event.

Query

A Query defines criteria for selecting events in the event store.

FieldTypeDescription
itemsrepeated QueryItemA list of selection criteria (logical OR).

An Event is selected if any QueryItem matches or the items field is empty.

Include in:

Query Item

A QueryItem defines a criterion for matching events.

FieldTypeDescription
typesrepeated stringList of event types (logical OR).
tagsrepeated stringList of tags (logical AND).

A QueryItem will match an Event if:

  • one of its types matches the Event.event_type or its types field is empty; AND
  • all of its tags match one of the Event.tags or its tags field is empty.

Include in:

  • Query to define which events to select.

Sequenced Event

A SequencedEvent represents a recorded Event along with its assigned sequence number.

FieldTypeDescription
positionuint64The sequence number.
eventEventThe recorded event.

Included in:

Error Response

An ErrorResponse is used to return errors from the gRPC API.

FieldTypeDescription
messagestringHuman-readable description of the error.
error_typeErrorTypeClassification of the error.

If an operation fails, the server will return a gRPC error response with a suitable gRPC status code and a human-readable message string. In addition, the gRPC status details attribute will have a serialised ErrorResponse message that has the same human-readable message string, and an error_type set to a appropriate ErrorType.

Error Type

The ErrorType enum indicates UmaDB error types returned within an ErrorResponse .

ValueNameDescription
0IOInput/output error (e.g. storage or filesystem).
1SERIALIZATIONSerialization or deserialization failure.
2INTEGRITYLogical integrity violation (e.g. condition failed).
3CORRUPTIONCorrupted or invalid data detected.
4INTERNALInternal server or database error.
5AUTHENTICATIONClient-server authentication error.
6INVALID_ARGUMENTRequest contains an invalid argument.

Summary

CategoryMessageDescription
Event ModelEvent, SequencedEventCore event representation.
QueriesQuery, QueryItemDefine filters for event selection.
ConditionsAppendConditionControl write preconditions.
Read/WriteReadRequest, ReadResponse, AppendRequest, AppendResponseReading and appending APIs.
MetaHeadRequest, HeadResponseRetrieve current head position.
TrackingTrackingRequest, TrackingResponseRetrieve current head position.
ErrorsErrorResponseConsistent error representation.

Released under the MIT License.