JunoDB Overview: PayPal's Open-Source Key-Value Store and Latency Bridging

Arpit Bhayani

Arpit Bhayani

May 23, 2023 • 7 min read

Play

JunoDB Overview: PayPal’s Open-Source Key-Value Store

JunoDB is a distributed, high-performance key-value store developed and open-sourced by PayPal. Within PayPal’s infrastructure, JunoDB powers critical backend workloads including authentication, user login, fraud and risk management, and financial transaction processing.

While relational databases act as the ultimate source of truth for financial ledgers due to strict ACID guarantees, JunoDB operates as a persistent, high-throughput caching and storage layer that shields underlying databases, maintains extreme availability, and resolves distributed data consistency challenges across active-active data centers.


1. Scale, Availability, and Key Guarantees

Operating at PayPal’s scale imposes extreme non-functional requirements on storage infrastructure:

  • Request Volume: Serves upwards of 350 billion requests per day.
  • Availability Guarantees: Designed for six nines (99.9999%) of availability, translating to no more than 31.56 seconds of total downtime per year.
  • Storage Model: Hybrid in-memory and persistent on-disk storage. Unlike pure in-memory stores, data in JunoDB can survive node restarts and persist across extended periods.
  • Configurable TTLs (Time-To-Live): Ranging from a few seconds (e.g., one-time passwords, short-lived session tokens) to several days (e.g., account profile metadata, user preferences, transaction idempotency records).

2. Architectural Evolution: Moving from C++ to Go

One of the most notable technical design decisions behind JunoDB is its programming language evolution.

The Initial Prototype: Single-Threaded C++

JunoDB was initially conceived as a single-threaded C++ service, heavily influenced by Redis’s architecture. Redis handles concurrency via a single-threaded event loop (using I/O multiplexers like epoll or kqueue), which completely eliminates lock contention, mutex overhead, and race conditions.

However, PayPal discarded this design and chose to completely rewrite JunoDB in Go (Golang).

Why Redis is Single-Threaded vs. Why JunoDB Needs Multi-Core Concurrency

AttributeRedis ArchitectureJunoDB Architecture
Primary BottleneckMemory-bound & Network I/O-boundCPU-bound & Network-bound
Execution ModelSingle-threaded event loopMulti-threaded concurrency via Go routines
Hardware UtilizationUtilizes 1 core (leaves remaining cores idle)Symmetrically utilizes all available CPU cores
Workload ProfileFast, simple in-memory pointer lookupsCryptographic hashing, replication checks, on-disk persistence, dynamic serialization
Traditional Redis on a 32-core machine:
[Core 1: 100% Active Event Loop] [Core 2-32: Idle / OS Only]

JunoDB on a 32-core machine:
[Core 1] [Core 2] [Core 3] ... [Core 32]  <-- M:N Goroutine Scheduler distributes CPU-bound operations

The Golang Advantage

  1. High Concurrency via Goroutines (Fibers/User-Space Threads): Goroutines start with a minimal stack footprint (around 2KB) and dynamically grow. They multiplex over OS kernel threads via Go’s M:N runtime scheduler without incurring the heavy context-switching cost of POSIX threads (pthreads).
  2. Multi-Core Exploitation for CPU-Heavy Tasks: Because JunoDB performs computationally expensive tasks—such as encryption, data compression, TTL maintenance, persistence coordination, and cross-cluster replication checks—a single core quickly saturates. Multi-threaded Go routines allow JunoDB to exploit 32-core, 64-core, or 128-core bare-metal machines natively.

3. Core Enterprise Use Cases

Offloading Relational Databases (RDBMS)

Relational engines (such as Oracle or PostgreSQL) are critical for transactional banking ledgers due to ACID compliance. However, complex multi-table joins, aggregations, and high-frequency point-lookups quickly exhaust relational connection pools and disk I/O. JunoDB caches precomputed query responses, shielding the RDBMS from repeated identical lookups.

Inter-Service Microservice Decoupling

In microservice architectures, upstream services routinely depend on downstream services for semi-static context (e.g., account status, user configurations). High traffic can cause cascading failures across dependency graphs. JunoDB acts as a shared, highly available intermediary caching tier, allowing dependent services to retrieve downstream data without making real-time RPC calls to the originating service.

Distributed Idempotency Management

In financial systems, duplicate execution of payment flows due to network drops, client retries, or lost acknowledgments can lead to double spending. JunoDB provides the distributed locking and state storage required for idempotency keys:

  1. A request enters the system with a unique idempotency key (e.g., UUID-txn-98412).
  2. The system checks JunoDB atomically for the existence of that key.
  3. If the key exists, the request is flagged as an in-flight or completed retry, and duplicate processing is bypassed.
  4. If the key does not exist, it is written to JunoDB with a finite TTL, and the payment workflow proceeds safely.

4. Deep Dive: Solving Latency Bridging in Active-Active Topologies

Perhaps the most sophisticated problem JunoDB addresses for PayPal is Latency Bridging across multiple geographic data centers.

The Active-Active Relational Replication Dilemma

PayPal operates active-active data center topologies using Oracle as their primary relational database. This introduces a fundamental distributed consistency dilemma:

  • Synchronous Replication across Data Centers: Writing to Data Center 1 (DC1) and blocking until Data Center 2 (DC2) confirms the write ensures immediate global consistency, but the speed-of-light network latency across data centers tanks write throughput and increases tail latency.
  • Asynchronous Replication across Data Centers: Writes return immediately after persisting locally in DC1, and are replicated asynchronously to DC2. While write throughput remains high, this introduces a replication lag window.
Client Write ---> DC1 Oracle (Persisted)

                      │ (Slow Asynchronous Replication Lag)

                  DC2 Oracle (Stale for X milliseconds/seconds)

The Problem: Read-Your-Writes Inconsistency

If a client initiates a state-altering operation (e.g., sends money or updates an auth state) that writes to DC1, and their subsequent request is routed to DC2 (due to geo-DNS routing, load balancing, or network failover), DC2’s Oracle database may not have received the asynchronously replicated record yet.

Result: The client gets a “Record Not Found” or reads a stale state, violating the Read-Your-Writes consistency model.

The Solution: Latency Bridging via JunoDB

JunoDB features near-instant, ultra-low-latency inter-cluster replication. By deploying JunoDB alongside the relational layer in each data center, PayPal uses JunoDB to “bridge” the latency window of the primary database.

sequenceDiagram
    autonumber
    actor Client
    participant DC1_App as DC1 Application Service
    participant DC1_Oracle as DC1 Oracle Database
    participant DC1_Juno as DC1 JunoDB Cluster
    participant DC2_Juno as DC2 JunoDB Cluster
    participant DC2_Oracle as DC2 Oracle Database
    participant DC2_App as DC2 Application Service

    Client->>DC1_App: Write Request (e.g., Update Token/Record)
    activate DC1_App
    DC1_App->>DC1_Oracle: 1. Persist Transaction (ACID)
    DC1_App->>DC1_Juno: 2. Write State Key-Value
    DC1_App-->>Client: Success Acknowledgment
    deactivate DC1_App

    par Fast KV Inter-Cluster Replication
        DC1_Juno->>DC2_Juno: Near-Instant Replication (< a few ms)
    and Slow RDBMS Replication
        DC1_Oracle-->>DC2_Oracle: Asynchronous DB Replication (Slower Lag Window)
    end

    Note over Client, DC2_App: Network failover or follow-up request routed to DC2
    Client->>DC2_App: Subsequent Read Request
    activate DC2_App
    DC2_App->>DC2_Juno: Check JunoDB for Updated Key
    alt Key Present in JunoDB (Latency Bridged)
        DC2_Juno-->>DC2_App: Return Fresh Data
        DC2_App-->>Client: Return Consistent State
    else Key Not in JunoDB (Fallback to DB)
        DC2_App->>DC2_Oracle: Read from Primary Database
        DC2_Oracle-->>DC2_App: Return DB Record
        DC2_App-->>Client: Return Data
    end
    deactivate DC2_App

Mechanics of Latency Bridging

  1. Dual Write at Origin: When an update occurs in DC1, the application writes to the local Oracle DB and concurrently writes the updated state to the local JunoDB cluster.
  2. Fast Cross-Cluster Synchronization: JunoDB replicates the record to the JunoDB cluster in DC2 with sub-millisecond to low-millisecond network propagation, far faster than complex transactional database replication streams.
  3. Early Read Redirection: When a subsequent read hits DC2, the service checks DC2’s local JunoDB cluster first. Even though DC2’s Oracle instance is still waiting for asynchronous log replication to catch up, JunoDB already possesses the updated data.
  4. Seamless Hand-off: By the time the short-lived JunoDB key expires or is invalidated, Oracle’s cross-DC replication has completed, achieving global data convergence without degrading write throughput.

5. Summary and Key Takeaways

  • Multi-Core Over Single-Threaded: JunoDB transitioned from single-threaded C++ to Go to capitalize on multi-core CPU architectures via goroutines, catering directly to compute-intensive, CPU-bound workloads that Redis’s single-threaded model does not target.
  • Production Resilience: Delivering six nines (99.9999%) of availability across 350 billion requests daily, JunoDB combines in-memory speed with durable on-disk persistence.
  • Architectural Latency Bridging: Rather than sacrificing write throughput by forcing an RDBMS into cross-region synchronous replication, pairing an RDBMS with an ultra-fast replicating distributed key-value store guarantees read-your-writes consistency across active-active data center topologies.
Arpit Bhayani

Principal Engineer II at Razorpay - building Agent Studio, Ex-staff engg at GCP Memorystore & Dataproc, Creator of DiceDB, ex-Amazon Fast Data, ex-Director of Engg. SRE and Data Engineering at Unacademy. I spark engineering curiosity through my no-fluff engineering videos on YouTube and my courses