Skip to main content
StackRoleYearStatus
—Lead Systems Architect & Full-Stack Developer2026Live
Inkly — Secure, High-Availability Messaging Architecture Architecture Diagram - Hero Preview by Ancel Ajanga.

Inkly — Secure, High-Availability Messaging Architecture

Zero-Knowledge privacy with horizontal WebSocket scaling and resilient 3-tier storage. Developed by Ancel Ajanga.

Written by Ancel Ajanga — Senior Software Engineer
Lead Systems Architect & Full-Stack Developer
Ongoing (2026)
Live

Inkly is a secure messaging architecture built around zero-knowledge privacy: encryption keys are derived on the client, so the server routes messages without being able to read them. It combines a PostgreSQL, MongoDB and Redis storage design with WebSocket delivery and an offline-first Flutter client.

The Problem

The primary engineering challenge in secure messaging is the 'Privacy-Performance-Scale' trilemma. Existing solutions typically sacrifice one of the three: 1. Centralized trust models (e.g., standard TLS-only backends) are fast and scalable but vulnerable to server-side compromise. 2. Traditional E2EE models often suffer from performance bottlenecks in key management and cross-device synchronization. 3. High-concurrency messaging systems often centralized real-time state, creating massive bottlenecks when scaling out WebSocket nodes. Inkly was specifically designed to handle three critical failure points: the scale-out bottleneck of real-time state across distributed Node.js nodes, the high-latency 'sync-storm' that occurs when mobile clients reconnect after long partitions and the requirement for a Zero-Knowledge security model that is invisible to the user but cryptographically impenetrable to the infrastructure provider.

To bridge the gap between absolute privacy and high-speed delivery, I architected a stateless backend that treats every message as an encrypted opaque blob, while leveraging a distributed Redis Pub/Sub backbone to coordinate real-time delivery across N nodes without a singular point of state failure.

The Solution

The solution is a distributed, reactive messaging engine where the backend serves as a high-speed, cryptographic router rather than an authoritative data owner. By implementing a 'Sacred Bond' lifecycle—where all encryption keys are derived on the client and never transmitted—the server is reduced to a coordinator of blinded events. Scalability is achieved by decoupling the WebSocket connection from the business logic through a Redis-backed adapter, enabling the control plane to scale horizontally to 10k+ concurrent sessions. Reliability is maintained through a hybrid data strategy: PostgreSQL for relational vault state, MongoDB for high-volume message indexing and Redis for distributed locking and rate-limiting. The result is a messaging system that guarantees E2EE privacy without sacrificing the sub-100ms real-time feel expected of modern production applications.

Key Technical Terms

  • Sacred Bond (X25519/HKDF):A cryptographic trust model where partners derive unique session keys on-device. The backend only sees a 'Bond ID' (a blinded hash) and encrypted metadata, ensuring absolute Zero-Knowledge isolation.
  • Horizontal WebSocket Adapter:A Redis Pub/Sub backbone that allows WebSocket messages to be routed between distributed nodes. If user A is on Node 1 and user B is on Node 2, the system bridges the broadcast instantly via the Redis bus.
  • Causal Message Ordering:A protocol ensuring messages are delivered in the order they were sent relative to each other, even over unreliable or high-latency mobile networks, preventing 'out-of-order' synchronization bugs.

The Impact

Inkly is a reference architecture for private real-time messaging. The server acts as a cryptographic router rather than an owner of readable data, with message state handled across PostgreSQL, MongoDB and Redis. It is about 92% complete. No user counts, connection capacity or latency figures are claimed.

Zero-Knowledge

Keys are derived on the client and the server cannot read message content

WebSockets

Real-time delivery with an offline outbox queue on the client

3-tier

PostgreSQL for identity, MongoDB for messages, Redis for ephemeral state

Flutter + Riverpod

Offline-first mobile client

Architecture Deep-Dive

The Inkly architecture is split into three distinct layers of responsibility: 1. Persistence Layer: We use a multi-primary PostgreSQL cluster for 'Vaults' (relational metadata, identity and audit trails), while MongoDB handles the high-volume 'Message Shards' where speed and unstructured data expansion are prioritized. Redis serves as the 'Global Brain,' managing distributed locks (Redlock), rate-limiting buckets and ephemeral transport state. 2. Orchestration Layer: A stateless cluster of NestJS nodes handles WebSocket handshakes and JWS validation. Using a Redis-backed WebSocket adapter, the system achieves cross-node communication. When a node receives a message for a client connected elsewhere, it broadcasts a targeted event via Redis, which the correct node picks up and pushes to the client in <10ms. 3. Client Layer: The Flutter-based mobile client implements an offline-first architecture using drift (SQLite) for high-performance local persistence. It manages the 'Sacred Bond' lifecycle independently, only sending encrypted packets to the backend. This ensures the backend remains a 'blind' transport layer, unable to inspect or modify message content.

Key Engineering Decisions

Designing Inkly required several high-stakes technical trade-offs: - Hybrid Storage vs. Unified DB: I chose PG + MongoDB over a single database to optimize for two different extremes: the rigid transactional integrity required for identity (PG) and the high-volume, low-latency write throughput required for messaging (MongoDB). This increases operational complexity but ensures the system doesn't buckle under specific load types. - Redis Pub/Sub vs. RabbitMQ: I initially considered RabbitMQ for more robust persistence, but opted for Redis Pub/Sub to maintain a latency target of sub-100ms for real-time delivery. We trade off 'guaranteed' disk-persistent MQ delivery for massive speed, handling persistence at the database layer instead. - Zero-Knowledge vs. Server-Side Features: By choosing a Zero-Knowledge model, we lose the ability to perform server-side message searching or AI filtering. I compensated for this by architecting a high-performance local search index on the client using SQLite, ensuring the privacy goal wasn't compromised for 'convenience' features.

Performance & Scalability

Inkly is designed to spread WebSocket connections across several nodes, but it has not been load-tested to a specific connection count, so no capacity or latency figures are claimed. The hard part of scaling WebSockets is that a message's recipient may be connected to a different node from its sender. Inkly handles this with a Redis-backed WebSocket adapter: the receiving node publishes a targeted event on Redis, and the node holding the recipient's connection delivers it. Because shared state lives in Redis, nodes can be added without reconfiguring the client, and the load balancer stays at the network edge.

Failure Modes & Resilience

Resilience is the cornerstone of the Inkly backend. We've mapped and mitigated four primary failure modes: 1. Redis Backbone Failure: If the Redis pub/sub layer fails, nodes degrade to single-node delivery. Users on the same node can still communicate, while cross-node messages are queued or rejected with a 'Service Unavailable' state, preventing silent message loss. 2. Database Latency Spikes: We use Opossum circuit breakers on all database calls. If MongoDB experiences a read/write spike, the circuit opens and the system switches to a 'Degraded Write' mode where messages are cached in Redis and asynchronously retried, preserving the real-time experience. 3. Network Partition (The Sync-Storm): Mobile clients often lose connection. Upon reconnection, we use a 'Causal Recovery' protocol that identifies exactly which messages were missed using sequence hashes rather than time-stamps, preventing duplicate deliveries and ensuring ordering integrity. 4. Identity Vault Exhaustion: Critical identity paths (PostgreSQL) are protected by bulkheads. Non-critical features like avatar updates or analytics cannot exhaust the connection pool required for message delivery or authentication.

Security & Trust Boundaries

Inkly operates under a 'Zero-Trust' and 'Zero-Knowledge' mandate. Security is not an afterthought; it is the infrastructure. - The Sacred Bond Lifecycle: Key exchange uses X25519 (Elliptic Curve Diffie-Hellman) for forward-secret session keys. HKDF is used for multi-layered key derivation, ensuring that even if one session key is compromised with future quantum-computing shortcuts, the root identities remain isolated. - Metadata Blinding: We blind the 'Bond ID'—the identifier that links two users—using a server-side pepper and a client-side salt. This ensures that even a database dump of the Inkly backend doesn't reveal who is communicating with whom. - Cryptographic Kill-Switch: In the event of a device theft, a user can broadcast a signed 'Kill-Switch' intent that immediately invalidates all active bonds and instructs partners to purge local caches, a feature normally only found in enterprise-grade security suites.

Frontend Engineering & UX

The Inkly frontend is a high-performance reactive system built with Flutter and Riverpod. UX decisions are driven by the requirement for 'Zero-Latency Feel' even over 3G/4G networks. - Offline-First Integrity: All outgoing messages enter an 'Outbox Queue' in a local drift (SQLite) database. They are optimistically rendered in the UI with a 'pending' state and synced with the backend only when the WebSocket heartbeat is stable. - Reactive State Management: Riverpod ensures that incoming messages trigger surgical UI updates without re-rendering the entire message list, maintaining a fluid 60fps scrolling experience even in chat rooms with 5,000+ messages. - Binary Efficiency: We use Protocol Buffers (Protobuf) for WebSocket payloads, reducing data usage by 40% compared to standard JSON, which is critical for users in high-data-cost regions like Kenya.

Outcome & Future Potential

Inkly is a reference architecture for private real-time messaging. The server acts as a cryptographic router rather than an owner of readable data, with message state handled across PostgreSQL, MongoDB and Redis. It is about 92% complete. No user counts, connection capacity or latency figures are claimed.

Zero-Knowledge

Encryption Model

Keys are derived on the client and the server cannot read message content

WebSockets

Transport

Real-time delivery with an offline outbox queue on the client

3-tier

Storage

PostgreSQL for identity, MongoDB for messages, Redis for ephemeral state

Flutter + Riverpod

Client

Offline-first mobile client

Key Engineering Takeaways

  • Privacy is a technical guarantee, not a policy; move secrets to the client-side.

  • Horizontal scaling of real-time state is best handled at the cache layer (Redis), not the DB.

  • Resilience requires circuit breakers and causal ordering to survive high-latency mobile networks.

  • Reactive UI and binary protocols (Protobuf) are essential for a premium mobile experience.

  • High-availability systems must be 'fail-aware'—failing closed for security and open for non-critical features.

Project Gallery

Inkly — Secure, High-Availability Messaging Architecture Architecture Diagram - Screenshot 1 by Ancel Ajanga.