Design a Secure Multi-Region Log Aggregation Pipeline
System DesignModel answerLast updated
Design a system that collects, encrypts, and stores logs from distributed edge nodes into centralized storage while ensuring confidentiality and integrity.
Problem Statement
You need to design a log aggregation system for a company operating hundreds of distributed edge locations worldwide. The system must collect security and application logs, protect them cryptographically, and store them in a centralized repository for compliance and forensic analysis.
Requirements
Functionality:
- Ingest structured JSON logs from local collection agents at each edge site
- Aggregate logs into a centralized, long-term storage system
- Support querying historical data for audit and investigation purposes
Security:
- Logs must be encrypted before leaving each edge location
- The central aggregation infrastructure should not have access to plaintext log data
- Support periodic cryptographic key updates without service disruption
Performance:
- Handle aggregate throughput of 500,000 log entries per second across all locations
- Minimize performance impact on edge applications generating logs
Reliability:
- Tolerate temporary network failures between edge sites and central infrastructure
- Detect and report any data loss or tampering
Design Scope
Your design should cover:
- Cryptographic architecture: How will you encrypt logs while keeping decryption keys away from the aggregation layer?
- System components: Describe the path from log generation to final storage, including intermediate layers
- Integrity verification: How will you detect unauthorized modifications or missing data?
- Operational concerns: How will the system handle key lifecycle management and maintain low latency?
Assumptions
- You have access to a distributed coordination service (like etcd or ZooKeeper)
- Standard protocols and open-source components are preferred
- Each edge location runs trusted agents, but the network and central systems are untrusted for confidentiality
Hints
Hint 1
Consider using asymmetric encryption so edge nodes only need public keys
Hint 2
Batching and compression before encryption will improve throughput
Hint 3
Chain batches together with hashes to detect gaps and tampering
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Solution: Secure Multi-Region Log Aggregation
This problem evaluates your ability to combine cryptographic principles with distributed systems design. The key insight is recognizing that the aggregation infrastructure is untrusted for confidentiality, which shapes every architectural decision.
1. Establish Requirements and Scale
Start by quantifying the workload:
Throughput: 500K events/second globally with ~1 KB average event size equals approximately 500 MB/s raw data. With compression (typically 5:1 for JSON logs), expect about 100 MB/s on the wire and roughly 9 TB/day in storage.
Per-location distribution: With 300 edge sites, average load is ~1,700 events/s per site, but traffic skew means busy locations may see 10–20x this rate. Design agents to handle peak loads of 50K events/s.
Latency tolerance: Logs are for audit and forensic use, not real-time alerting. End-to-end delivery within minutes is acceptable. Local logging calls must complete in microseconds.
Durability: Logs must be retained for years with regulatory compliance (WORM storage). The system should provide at-least-once delivery with mechanisms to detect gaps.
2. Cryptographic Design: Envelope Encryption
The core challenge is encrypting logs at the edge without giving edge nodes the ability to decrypt centralized data, while still allowing authorized queries.
Use asymmetric envelope encryption:
- A Hardware Security Module (HSM) or centralized KMS generates Key Encryption Key (KEK) pairs (X25519 for HPKE per RFC 9180)
- The private KEK never leaves the HSM and is only accessible to the authorized query service
- Public KEKs are published to a distributed config store where edge agents can fetch them
- For each batch of logs, the agent:
- Generates a random Data Encryption Key (DEK)
- Encrypts the batch using AES-256-GCM with the DEK
- Encrypts (wraps) the DEK using the public KEK via HPKE
- Discards the DEK from memory
- Sends both encrypted logs and wrapped DEK
Result: The aggregation pipeline, message queues, and storage all contain only ciphertext. Compromise of these components reveals nothing. Only the query service, accessing the HSM, can unwrap DEKs and decrypt specific log batches.
Key rotation:
- Generate KEK version N+1 and publish it with a future activation timestamp
- Edge agents preload the new key by watching the config store
- At the activation time, agents switch to the new version
- Old private keys remain in the HSM marked "decrypt-only" for historical data
- To retire old keys, run a batch job that unwraps and re-wraps DEKs using only the HSM—data blobs are never decrypted
3. System Architecture
Application → Agent (local spool) → Regional Gateway → Regional Queue
→ Central Queue → Archiver → Object Storage + Metadata Index
Log Agent (at each edge site):
- Receives logs via shared memory or Unix socket (non-blocking, fire-and-forget)
- Batches logs (~1 MB or 1 second intervals)
- Compresses using zstd (must happen before encryption)
- Encrypts with AES-256-GCM using a fresh DEK per batch
- Wraps DEK with current public KEK
- Signs batch with host-specific Ed25519 key
- Spools to local Write-Ahead Log (WAL) for durability
- Streams to regional gateway over mTLS
Regional Gateways (stateless):
- Verify signatures and sequence numbers per host
- Forward to regional Kafka cluster
- Acknowledge only after Kafka confirms commit
Message Queue (Kafka):
- Regional clusters with replication factor 3
- Partition by host_id to preserve per-host ordering
- MirrorMaker replicates to central cluster
- Retain 3–7 days as a replay buffer
- Size for ~300 partitions to handle 100 MB/s compressed
Archivers:
- Subscribe to central Kafka
- Deduplicate on batch_id (host_id, sequence)
- Concatenate batches into ~256 MB objects
- Write to object storage with WORM/Object Lock enabled
- Index plaintext metadata (time, location, log type, key version) for queries
Query Service:
- Reads index to find relevant encrypted batches
- Pulls matching objects from storage
- Calls HSM to unwrap DEKs
- Decrypts and returns results
- All operations audited
4. Data Integrity Mechanisms
Authenticity: Each batch includes an Ed25519 signature over all fields, binding plaintext metadata to the encrypted content. GCM's authentication tag alone is insufficient because anyone can encrypt with the public KEK—the signature proves the batch originated from a specific trusted host.
Completeness: Agents assign monotonically increasing sequence numbers per host and include the hash of the previous batch. This hash chain allows detection of missing or reordered batches. Agents also send periodic heartbeats so silence is distinguishable from loss.
Tampering detection: AES-GCM provides authenticated encryption. The authentication tag covers both ciphertext and Additional Authenticated Data (AAD), which includes all plaintext metadata fields. Any modification breaks verification.
Audit trail: Archivers periodically compute Merkle trees over batch hashes and write the roots to immutable storage. This enables third-party verification that logs are complete and unmodified.
5. Performance Optimization
Agent-side:
- Use lock-free ring buffers for application writes (memcpy only, no blocking)
- Run compression, encryption, and network I/O on dedicated threads/cores
- Batch operations: one HPKE operation per ~1 MB batch (negligible overhead)
- AES-GCM with AES-NI hardware acceleration runs at several GB/s per core
- Cache public KEKs locally; watch config store for updates
Network:
- Use persistent HTTP/2 or gRPC connections to amortize TLS handshake costs
- Regional gateways provide geographic locality, reducing latency
Storage:
- Object storage provides unlimited scale and built-in durability
- Plaintext metadata indexing enables efficient queries without full-table scans
6. Key Design Trade-offs
Batch-level vs. field-level encryption: This design encrypts entire batches for simplicity and performance. Field-level encryption would allow selective decryption for specific fields (e.g., decrypt IP addresses but not request bodies), but adds complexity and makes queries slower. Choose based on query patterns.
Symmetric vs. asymmetric envelope: Using symmetric KEKs would require edge nodes to access a KMS on every batch (high latency, failure mode) or cache master keys locally (unacceptable security risk). Asymmetric encryption solves both problems: public keys can be freely distributed, and only the central HSM holds private keys.
At-rest vs. in-transit vs. in-use: This design provides encryption at-rest and in-transit. Logs are decrypted in-use only within the query service. For higher assurance, run the query service in a TEE (Trusted Execution Environment) or use homomorphic encryption for specific query types, though this adds significant complexity.
Durability vs. latency: The agent's local WAL provides the first durability guarantee. Kafka adds durability across network failures. Object storage provides long-term durability. Each layer trades latency for reliability. For even stronger guarantees, use synchronous replication to multiple regions before acknowledging, though this increases latency.
Common Mistakes
- Encrypting with symmetric keys stored at edge sites: If edge nodes hold decryption keys, compromising one site exposes logs from all sites sent through shared infrastructure.
- Ignoring authenticated encryption: Using encryption without authentication (e.g., AES-CBC without HMAC) allows tampering. Always use AEAD modes like GCM.
- Compressing after encryption: Ciphertext has high entropy and doesn't compress. Always compress first.
- Forgetting key rotation: Hard-coding or never rotating keys turns compromise into a permanent vulnerability.
- Blocking application threads: If log writes block on network I/O or crypto, applications will experience unacceptable latency spikes.
This design balances security, performance, and operational complexity, providing strong confidentiality and integrity guarantees while scaling to high throughput distributed environments.