Skip to main content

REST and gRPC API

Kahuna exposes sequence operations through REST and gRPC.

REST API​

All sequence REST APIs use POST.

EndpointPurpose
/v1/sequences/createCreate a persistent sequence.
/v1/sequences/updateRewrite sequence parameters and start a new incarnation.
/v1/sequences/getRead sequence metadata.
/v1/sequences/nextAllocate one value.
/v1/sequences/reserveAllocate a contiguous range.
/v1/sequences/deleteDelete a sequence.

Create​

curl -X POST https://localhost:8082/v1/sequences/create \
-H 'Content-Type: application/json' \
-d '{
"name": "orders",
"initialValue": 0,
"increment": 1,
"maxValue": null,
"blockSize": null,
"durability": "Persistent"
}'

Update​

curl -X POST https://localhost:8082/v1/sequences/update \
-H 'Content-Type: application/json' \
-d '{
"name": "orders",
"currentValue": 5000,
"increment": 1,
"blockSize": 100,
"durability": "Persistent"
}'

Use removeMaxValue: true or removeBlockSize: true to clear those optional settings. Omitting a field leaves the existing value unchanged.

Get​

curl -X POST https://localhost:8082/v1/sequences/get \
-H 'Content-Type: application/json' \
-d '{
"name": "orders",
"durability": "Persistent"
}'

Next​

curl -X POST https://localhost:8082/v1/sequences/next \
-H 'Content-Type: application/json' \
-d '{
"name": "orders",
"idempotencyKey": "request-123",
"durability": "Persistent"
}'

Response allocation:

{
"type": "Success",
"allocation": {
"name": "orders",
"start": 1,
"end": 1,
"count": 1,
"revision": 1
},
"revision": 1
}

Reserve​

curl -X POST https://localhost:8082/v1/sequences/reserve \
-H 'Content-Type: application/json' \
-d '{
"name": "orders",
"count": 100,
"idempotencyKey": "batch-456",
"durability": "Persistent"
}'

Delete​

curl -X POST https://localhost:8082/v1/sequences/delete \
-H 'Content-Type: application/json' \
-d '{
"name": "orders",
"durability": "Persistent"
}'

gRPC API​

The gRPC service is named Sequencer:

service Sequencer {
rpc CreateSequence (GrpcCreateSequenceRequest) returns (GrpcSequenceResponse);
rpc UpdateSequence (GrpcUpdateSequenceRequest) returns (GrpcSequenceResponse);
rpc GetSequence (GrpcGetSequenceRequest) returns (GrpcSequenceResponse);
rpc NextSequenceValue (GrpcNextSequenceRequest) returns (GrpcSequenceAllocationResponse);
rpc ReserveSequenceRange (GrpcReserveSequenceRangeRequest) returns (GrpcSequenceAllocationResponse);
rpc DeleteSequence (GrpcDeleteSequenceRequest) returns (GrpcSequenceResponse);
}

Response Types​

TypeMeaning
SuccessThe operation succeeded.
NotFoundThe sequence does not exist.
AlreadyExistsCreate was called for an existing sequence.
InvalidInputThe name or request parameters were invalid.
MaxValueExceededThe requested allocation would exceed MaxValue.
MustRetryThe operation should be retried. Allocations also return this while a sequence update is waiting out the block lease.
AbortedThe operation was aborted.
ErrorAn unexpected error occurred.