Skip to content

Protobuf Format

The Protobuf wire format is a Layer 2 specification that defines how OJS job envelopes are serialized using Protocol Buffers. It provides a compact, efficient alternative to JSON for high-throughput deployments.

The Protobuf format uses the media type application/openjobspec+proto:

Terminal window
POST /ojs/v1/jobs
Content-Type: application/openjobspec+proto
Accept: application/openjobspec+proto

Backends that support Protobuf MUST also support JSON. Clients negotiate the format via Content-Type and Accept headers.

message JobEnvelope {
string id = 1;
string type = 2;
string queue = 3;
repeated google.protobuf.Value args = 4;
JobState state = 5;
int32 priority = 6;
int32 attempt = 7;
int32 max_attempts = 8;
google.protobuf.Timestamp created_at = 9;
google.protobuf.Timestamp scheduled_at = 10;
google.protobuf.Timestamp started_at = 11;
google.protobuf.Timestamp completed_at = 12;
RetryPolicy retry = 13;
UniquePolicy unique = 14;
map<string, google.protobuf.Value> meta = 15;
repeated JobError errors = 16;
}
enum JobState {
JOB_STATE_UNSPECIFIED = 0;
JOB_STATE_SCHEDULED = 1;
JOB_STATE_AVAILABLE = 2;
JOB_STATE_PENDING = 3;
JOB_STATE_ACTIVE = 4;
JOB_STATE_COMPLETED = 5;
JOB_STATE_RETRYABLE = 6;
JOB_STATE_CANCELLED = 7;
JOB_STATE_DISCARDED = 8;
}
message RetryPolicy {
int32 max_attempts = 1;
google.protobuf.Duration initial_interval = 2;
double backoff_coefficient = 3;
google.protobuf.Duration max_interval = 4;
bool jitter = 5;
repeated string non_retryable_errors = 6;
string on_exhaustion = 7;
}
RangePurpose
1–19Core fields (defined by this spec)
20–99Reserved for future OJS fields
100+Extension fields
OJS TypeProtobuf Type
stringstring
integerint32 / int64
numberdouble
booleanbool
timestampgoogle.protobuf.Timestamp
durationgoogle.protobuf.Duration
anygoogle.protobuf.Value
mapmap<string, Value>

Protobuf and JSON formats MUST round-trip losslessly. A job serialized to Protobuf, then deserialized back to JSON, MUST produce an identical JSON document (modulo field ordering).

Protobuf provides approximately 40–60% size reduction compared to JSON, with faster serialization and deserialization. This matters most in high-throughput scenarios (10,000+ jobs/sec) and bandwidth-constrained environments.

The ojs-proto/ repository uses Buf for linting and code generation:

Terminal window
buf lint # Lint proto files
buf generate # Generate Go + TypeScript code

Generated code includes full gRPC client and server stubs for both Go and TypeScript.