Server API Implementation
HTTP API server implementation for telemetry-kit.dev ingestion service
Overview
The telemetry-kit server is a complete HTTP API implementation using the Axum framework. It connects all core components (Event Schema validation, DO_NOT_TRACK middleware, SYNC_PROTOCOL specification) into a functional, production-ready service.
This documentation covers the server implementation details. For self-hosting instructions, see the Self-Hosting Guide.
Architecture
Hexagonal Architecture
API Endpoints
Health Check
Returns server health status for monitoring and load balancers.
Response:
Use Cases:
- Kubernetes liveness probes
- Load balancer health checks
- Monitoring systems
- Deployment verification
Event Ingestion
Receives batches of telemetry events from SDK clients.
Required Headers:
| Header | Description | Example |
|---|---|---|
Content-Type | Must be application/json | application/json |
X-Signature | HMAC-SHA256 signature | a1b2c3d4... |
X-Timestamp | Unix timestamp | 1700000000 |
X-Nonce | UUID v4 for replay prevention | 550e8400-e29b-41d4-a716-446655440000 |
X-Batch-Size | Number of events in batch | 10 |
X-SDK-Version | SDK identifier | telemetry-kit-rust/0.3.0 |
X-Schema-Version | Event schema version | 1.0.0 |
Request Body:
Response Formats
Success (200 OK)
All events accepted:
Partial Success (207 Multi-Status)
Some events rejected:
Error Response Format
All errors follow a consistent format:
Validation Rules
Batch Validation
| Rule | Limit | Error |
|---|---|---|
| Max batch size | 1000 events | 413 Payload Too Large |
| Max payload size | 5 MB | 413 Payload Too Large |
Event Validation
| Field | Rule | Example |
|---|---|---|
schema_version | Must be 1.0.0 | "1.0.0" |
user_id | Must start with anon_ + 64 hex chars | "anon_a1b2..." |
user_id length | Exactly 69 characters | - |
service.name | Cannot be empty | "my-app" |
event.type | Cannot be empty | "command" |
timestamp | Within 7 days of current time | - |
HMAC Authentication
Signature Calculation
Example (Python):
Security Features
- HMAC-SHA256 - Cryptographically secure request signing
- Timestamp validation - ±5 minutes tolerance prevents replay attacks
- Nonce validation - UUID v4 format for uniqueness
- Constant-time comparison - Prevents timing attacks
Middleware Stack
The server applies middleware in this order:
- CORS - Cross-Origin Resource Sharing (configurable)
- Request Tracing - Logging and observability
- DO_NOT_TRACK - RFC 7842 compliant (for ingestion routes)
- HMAC Validation - Request signing (for ingestion routes)
Configuration
Environment Variables
Configuration Files
The server loads configuration in priority order:
config/default.toml- Base configurationconfig/{environment}.toml- Environment-specific- Environment variables with
APP_prefix
Defaults
| Setting | Default |
|---|---|
| Host | 0.0.0.0 |
| Port | 8080 |
| Max batch size | 1000 events |
| Max payload size | 5 MB |
| Timestamp tolerance | ±5 minutes |
| Nonce TTL | 10 minutes |
Error Types
| Code | Status | Description |
|---|---|---|
bad_request | 400 | Malformed request |
unauthorized | 401 | Missing or invalid authentication |
not_found | 404 | Endpoint not found |
validation_error | 422 | Event validation failed |
rate_limit_exceeded | 429 | Too many requests |
payload_too_large | 413 | Batch exceeds limits |
internal_error | 500 | Server error |
service_unavailable | 503 | Service temporarily unavailable |
Running the Server
Development
Production
Testing Endpoints
Health Check
Ingestion with HMAC
Performance
Latency (Estimated)
| Operation | Target |
|---|---|
| Health check | < 1ms |
| Ingestion (validation only) | < 10ms |
| With storage | < 50ms p99 |
Throughput (Estimated)
| Metric | Target |
|---|---|
| Requests/second | 1,000+ (single instance) |
| Events/second | 10,000+ (with batching) |
Resources
| Resource | Baseline |
|---|---|
| Memory | ~50MB |
| CPU | Low (async I/O bound) |
Security Considerations
Implemented
- HMAC-SHA256 request signing
- Timestamp validation (time window)
- Nonce format validation
- DO_NOT_TRACK support (RFC 7842)
- Anonymous user IDs
- Constant-time signature comparison
- Error message sanitization
Recommended for Production
- TLS/HTTPS termination (nginx, load balancer)
- Rate limiting (per-token quotas)
- Nonce deduplication cache (Redis)
- Token rotation strategy
- Network isolation
See Also
- Self-Hosting Guide - Deploy your own server
- API Reference - SDK API documentation
- Auto-Sync - Configure client syncing
- Privacy Compliance - GDPR/CCPA guide