Combining Cloudflare Durable Objects with Cap'n Proto for sub-millisecond serialization at global scale
@0xdbb9ad1f14bf495a;
struct TelemetryReading {
deviceId @0 :Text;
timestamp @1 :Int64;
sensorType @2 :SensorType;
value @3 :Float32;
unit @4 :Text;
location @5 :GeoPoint;
}
struct GeoPoint {
lat @0 :Float64;
lng @1 :Float64;
}
enum SensorType {
temperature @0;
humidity @1;
pressure @2;
motion @3;
}
export class TelemetryShard {
private state: DurableObjectState;
private storage: DurableObjectStorage;
constructor(state: DurableObjectState) {
this.state = state;
this.storage = state.storage;
}
async fetch(request: Request) {
const data = new CapnpReader(
await request.arrayBuffer()
);
await this.storage.put({
key: data.deviceId,
value: data.serialize()
});
return new Response('OK');
}
}
Cap'n Proto requires no parsing step. Data is memory-mapped and read directly, enabling microsecond-level serialization.
Durable Objects run at 300+ edge locations worldwide. Your telemetry data stays close to its source with automatic failover.
Each Durable Object maintains its own state with strong consistency. Perfect for device aggregation and time-series windowing.
Binary serialization is 60-80% smaller than JSON. Less bandwidth, lower egress costs, faster cold starts.
Schema-first design ensures all services agree on data structure. Breaking changes are caught at compile time.
Add new fields without breaking old clients. Cap'n Proto's evolutionary schema supports seamless versioning.