Skip to content

Quick Start

This guide walks you through creating your first log, appending events, and querying a view.

You’ll need:

First, obtain a JWT token by exchanging your API key:

Terminal window
curl -X POST https://api.primatomic.com/auth/token \
-H "Content-Type: application/json" \
-d '{"api_key": "your_api_key_here"}'

Response:

{
"access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 3600
}

Include this token in the Authorization header for all subsequent requests:

Terminal window
export TOKEN="eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9..."

Create an event log to store your events. Log names must be unique within your tenant:

Terminal window
curl -X POST https://api.primatomic.com/logs/my-events \
-H "Authorization: Bearer $TOKEN"

Response:

{
"success": true,
"log_id": "550e8400-e29b-41d4-a716-446655440000"
}

Save the log_id. All subsequent operations use it:

Terminal window
export LOG_ID="550e8400-e29b-41d4-a716-446655440000"

Append events to your log. Event payloads are sent as raw bytes:

Terminal window
curl -X POST https://api.primatomic.com/logs/$LOG_ID/append \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/octet-stream" \
-d '{"type":"user_signup","user_id":"123"}'

Response:

{
"success": true,
"sequence": 1
}

Store the sequence number if you need read-after-write consistency.

Views are WebAssembly components that process log events. The WASM binary must implement the primatomic:machine interface (see WASM Interface).

Terminal window
# Download the example counter WASM (ghcr.io/primatomic/counter:0.0.1)
wkg get primatomic:[email protected] --output counter.wasm
# Deploy it
curl -X POST https://api.primatomic.com/logs/$LOG_ID/views/counter \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary @counter.wasm

Response:

{
"success": true
}

Before querying, verify the view has a leader and is processing events:

Terminal window
curl https://api.primatomic.com/logs/$LOG_ID/views/counter/stats \
-H "Authorization: Bearer $TOKEN"

Response:

{
"view_name": "counter",
"log_name": "my-events",
"leader_status": "ready",
"leader_node_id": "node-1",
"processed_sequence": 1,
"created_at": 1705680000
}

When leader_status is "ready", the view is available for queries. If leader_status is null, wait and retry.

Query your view. You can specify a sequence number for read-after-write consistency:

Terminal window
# With read-after-write consistency (waits for sequence 1)
curl -X POST "https://api.primatomic.com/logs/$LOG_ID/views/counter/query?after=1" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary ""

Request/Response Format:

AspectSpecification
Request Content-Typeapplication/octet-stream
Request BodyBinary query input (format defined by view)
Response Content-Typeapplication/octet-stream
Response BodyBinary query output (format defined by view)

The response body format is defined by your view’s query function. The counter example returns JSON:

Terminal window
curl -s -X POST "https://api.primatomic.com/logs/$LOG_ID/views/counter/query?after=1" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/octet-stream" \
--data-binary ""
# Response: {"count":1}

If you omit the after parameter, the service may return stale results.

GuaranteeDescription
DurabilityEvents are not acknowledged until durably stored
Log OrderingSequence numbers are strictly monotonically increasing; each event stored exactly once
View ProcessingEvents processed in order; at-least-once (views must be deterministic)
ConsistencyQueries with after parameter reflect all events up to that sequence
IsolationTenants cannot access other tenants’ resources