AfterLink Protocol
A high-performance custom application-layer binary TCP protocol for Node.js, designed for sub-millisecond real-time communication.
10-Byte Header Frame Layout
Why AfterLink?
Standard protocols like HTTP and WebSockets carry heavy frame overhead (frame encoding, masking keys, padding) which adds serialization latency. AfterLink solves this by using a fixed 10-byte header frame followed by raw buffer streams.
By avoiding base64 encoding and text serialization, AfterLink reads and writes binary data straight to Node.js TCP Sockets, maintaining sub-millisecond response times even under high throughput.
- • Strict schemas: Integrated with Zod for binary payloads.
- • Persistent: Fully multiplexed, single socket channel.
- • Native Pub/Sub: High-performance event router in C++.
Performance Benchmarks
Throughput comparison under peak workloads (messages processed per second, local network testing)
Feature Matrix
| Feature | AfterLink | WebSocket | gRPC |
|---|---|---|---|
| Framing format | Binary (10B fixed header) | Text/Binary (Variable mask) | Protobuf stream (HTTP/2) |
| Validation layer | Zod Schemas (Runtime) | None (Manual validation) | Protobuf schemas (Compile) |
| Latency | Sub-1ms (0.033ms avg) | 1-3ms | 2-5ms |
| Pub/Sub support | Native & Multiplexed | Third-party required | Requires stream channels |
Lifecycle Flow
TCP Connection
Clients connect directly to the TCP socket server. Handshake verifies magic bytes (0xAF) to establish tunnel.
Frame Decoding
Data is read as buffer blocks. The header parser slices 10-byte offsets to extract length, route, and flag properties.
Zod Validation & Route
Payloads are validated against schemas on designated routes. Handled outputs are stream-broadcast back immediately.
Quick Start Example
// 1. Import AfterLink server
import { createServer } from 'afterlink';
import { z } from 'zod';
// 2. Initialize and declare schema validations
const server = createServer({ port: 8080 });
const UserMessageSchema = z.object({
userId: z.string(),
content: z.string()
});
// 3. Listen on routes
server.route('/chat', UserMessageSchema, (msg, socket) => {
console.log(`Message received from ${msg.userId}: ${msg.content}`);
// Broadcast response
server.broadcast('/chat', {
userId: 'system',
content: 'Message processed successfully.'
});
});
server.start(() => console.log('AfterLink listening on 8080')); Ready to integrate?
Get AfterLink on npm registry or clone the codebase on GitHub.