Spedo
SPEDO ENGINE
v0.70.0 PREVIEW
← Documentation

Spedo — Technical Lexicon & Architecture Reference Guide

Reference v0.64.0 — Product terms, protocol, persistence, and operations.

Support and documentation assistant

Target audience: Systems architects, C/Rust/Python engineers, SREs, and data engineering teams.

This lexicon describes the currently published technical contract. In case of discrepancies with earlier examples, the product maturity register and the persistence guide take precedence. Spedo remains a single-node engine: local recovery mechanisms are not high-availability (HA) cluster features.


v0.51 correctness and measurement concepts


📑 Table of Contents

1. Concurrency Model, Networking & Threading

2. C Client Accelerator & Zero-Copy Serialization

3. Reactive Variables & Real-Time Push Invalidation

4. State Machines & Distributed Workflow Orchestration

5. AI Vector Engine & SIMD Computing

6. Priority Queues & Fair Scheduling

7. Memory Density, Retention & Persistence

8. Persistence, Recovery & HA Boundaries

9. Data Structures & Memory Allocation

10. Python SDK, Synchronization & Data Models

11. Abbreviations, Variables and Conventions

12. Executive Summary for Technical Audits & Engineering Due Diligence


1. Concurrency Model, Networking & Threading

• CPU Affinity Attempt and SO_REUSEPORT (v0.50.0+)

• Adaptive Lease Observe Mode

• SO_REUSEPORT Multi-Workers vs Single-Thread Event Loop (Redis ae.c)

graph TD subgraph RedisThreading["Redis 7.4 Architecture"] C1["TCP Clients"] --> IO["I/O Threads (Socket Read)"] IO --> SingleThread["⚠️ 1 Single Central Thread (ae.c) - Command Execution"] SingleThread --> Dict["Global Hash Table"] end subgraph SpedoThreading["Spedo Multi-Core Architecture"] C2["TCP Clients"] --> KernelSO["Kernel SO_REUSEPORT Dispatch"] KernelSO --> W1["Tokio listener/task 1"] KernelSO --> W2["Tokio listener/task 2"] KernelSO --> W16["Tokio listener/task N"] W1 --> S1["256 Parallel Shards (RwLock)"] W2 --> S1 W16 --> S1 end

• Sharded Memory & Lock Striping vs Global Table dict.c (Redis)


• Lockless Atomic Clock vs server.lruclock & robj Bitfields (Redis)


• TCP_NODELAY & Nagle's Algorithm vs Default Network Buffering


• Epoll, Kqueue & IO_Uring (Asynchronous I/O Multiplexing)

- epoll : Scalable Linux I/O event notification facility.

- kqueue : High-performance event filter mechanism on macOS / FreeBSD.

- io_uring : Next-gen Linux interface using dual kernel/user-space shared ring buffers for zero-copy non-blocking asynchronous I/O.


• CAS (Compare-And-Swap) & CPU Atomic Primitives


2. C Client Accelerator & Zero-Copy Serialization

• spedo_core.c vs hiredis & redis-py

1. encode_command : Precomputes exact byte length and allocates a single contiguous raw memory buffer (malloc), serializing arguments via pointer arithmetic without allocating intermediate Python string objects.

2. decode_resp : Parses RESP protocol frames (+, -, :, $, *) in a single linear pass over the receive buffer with zero intermediate heap allocations.

3. execute_pipeline : Batches thousands of commands into a single sendall() syscall and decodes all responses in a tight C loop.


• GIL Release (Py_BEGIN_ALLOW_THREADS) vs GIL Contention


• Dynamic Buffer Shrinkage (maybe_shrink_buffer)


• RESP2 vs RESP3 (REdis Serialization Protocol v2 & v3)

- RESP2 : Historical standard limited to primitive types: Simple Strings (+), Errors (-), Integers (:), Bulk Strings ($), and Arrays (*).

- RESP3 : Modern extension introducing rich semantic types: Dictionaries / Maps (%), Sets (~), Booleans (#), Nulls (_), Doubles (,), Verbatim strings (=), and out-of-band asynchronous Push frames (>).


• Apache Arrow & Columnar Zero-Copy Format


• JSON RFC 7396 (JSON Merge Patch) vs RFC 6901 (JSON Pointer)

- RFC 7396 (JSON.MERGE) : Applies a recursive diff patch to an existing JSON document (overwrites supplied fields, deletes null fields, preserves untouched keys).

- RFC 6901 (JSON.GET /path) : Directly targets and extracts a specific nested path (/users/42/address/city).


3. Reactive Variables & Real-Time Push Invalidation

• SpedoLiveVar & SPEDO.WATCH vs Redis Client Side Caching (CLIENT TRACKING)

- SPEDO.WATCH registers the client socket in the server invalidation broadcast registry (broadcast::Sender).

- SpedoLiveVar caches the decoded value directly in the local RAM of the application process.

- Read : $0\text{ ms}$ network latency, instantaneous local RAM read ($< 0.0001\text{ ms}$, +2.56 million reads/s).

- Mutation : Whenever a key mutates on the server, a compact push invalidation frame is broadcast in real time. The client updates its local cache and immediately wakes waiting coroutines.

sequenceDiagram autonumber participant App as Python App (Pod A) participant LiveVar as SpedoLiveVar (Local RAM) participant Srv as Spedo Server participant Other as Other Pod (Pod B) Note over App,LiveVar: 1. Ultra-fast local memory read App->>LiveVar: val = live_var.value LiveVar-->>App: Instant data (0ms - 2.5M reads/s) Note over Other,Srv: 2. Mutation on another node Other->>Srv: SET config "dark_mode" Srv->>Srv: Shard Mutation & Invalidation Broadcast Note over Srv,LiveVar: 3. Real-time Push Invalidation Srv-->>LiveVar: Push frame: 'config' LiveVar->>LiveVar: Local RAM update & Event Trigger Note over App: 4. Notification / Await woke instantly App->>App: Callback @on_change executed

4. State Machines & Distributed Workflow Orchestration

• Workflow Engine ($O(1)$ Atomic Claim) vs Redis Streams & Lua Redlock

- WF.SUBMIT : Enqueues document into the step's FIFO queue ($O(1)$).

- WF.CLAIM : Atomically dequeues the next document and assigns an execution lease with TTL to a worker_id ($O(1)$).

- WF.TRANSITION : Validates completion of the current step and atomically moves the document to the next stage ($O(1)$).

- WF.RECOVER : Scans expired leases and requeues them only when a worker or scheduler explicitly invokes the command.


5. AI Vector Engine & SIMD Computing

• SIMD Cosine Similarity vs RediSearch Vector Index

- Built-in native vector search engine (src/storage/vectors.rs).

- On VECTOR.ADD, vectors are L_2-normalized upon insertion and stored as CPU-aligned contiguous memory blocks (repr(C) / Vec<f32>).

- VECTOR.SEARCH computes dot products via hardware vector instructions: AVX2 / AVX-512 / ARM NEON (executing 8 to 32 floating-point FMA operations per clock cycle).

- Maintains Top-K via a fixed-size BinaryHeap (Min-Heap) of size K, avoiding sorting the full dataset ($O(N \log K)$).


• Vector Quantization (SQ8 / Int8)

x_int8 = round(127 × (x - min) / (max - min))

- 4x RAM reduction (6.14 GB → 1.53 GB for 1M vectors).

- VNNI / AVX2 CPU acceleration : Computes 32 dimensions in a single CPU instruction instead of 8, accelerating search throughput by 2x to 4x while preserving 99.5% semantic fidelity.


• In-Situ Computing (In-DB) vs Ex-Situ Client Processing (NumPy/Pandas)

- Ex-Situ (Traditional) : Database returns raw payload over the wire (MGET, JSON.GET), client deserializes and executes computations (NumPy matrix multiply, attention KV-cache, logit filtering). Network and serialization create a massive bottleneck.

- In-Situ (Spedo) : Mathematical and vector computations execute directly in Spedo server RAM in Rust with SIMD hardware acceleration. Only the final scalar result or Top-K array is returned.


• GEMM (General Matrix Multiply) & FMA (Fused Multiply-Add)

- GEMM : Fundamental linear algebra operation C = α(A · B) + βC, at the core of Transformer attention layers and LLM inference.

- FMA : x86/ARM processor instruction computing a × b + c in a single clock cycle with a single numerical rounding step (high precision).


• Contiguous Matrix Engine (0.3 ns) vs Key-Value Hash Table (50-150 ns)

- Key-Value O(1) : Requires computing a hash (SipHash), bucket modulo division, traversing scattered DRAM pointers (Pointer Chasing), and string equality checks → 150 to 350 CPU cycles (50 to 150 ns).

- Contiguous Matrix O(1) : Pure arithmetic RAM offset offset = (row cols + col) 4 bytes → 1 CPU cycle (0.3 ns) with continuous hardware L1 cache-line prefetching (64 bytes).


6. Priority Queues & Fair Scheduling

• Spedo FairShare 7:2:1 — ordonnanceur batch pondéré et work-conserving

- QPUSH queue item [PRIORITY 0|1|2] [DELAY secs] [FAMILY tenant]

- Three priority tiers: P0 = Critical, P1 = Standard, P2 = Low-Priority/Batch.

- A canonical QPOP ... 10 batch targets 7 tasks from P0, 2 from P1 and 1 from P2 when all tiers have enough ready work.

- The ratio is per batch, not a persistent credit window across calls; count=1 is strict priority.

- If a tier is empty, its share is reassigned dynamically (surplus borrowing) so ready capacity is not wasted.

- Inside each tier, FAMILY buckets are interleaved round-robin for multi-tenant fairness.


7. Memory Density, Retention & Persistence

• COL, ColdArchive and Tiered Storage vs Eviction

flowchart LR subgraph RedisEviction["Standard Redis Eviction"] RMem["Memory Full (64 MB)"] --> REvict["Permanent Key Deletion"] REvict --> RLoss["⚠️ Data Lost Permanently"] end subgraph SpedoMemory["Spedo Memory Management"] SMem["Memory > Threshold"] --> SScan["COL / Eviction Policy"] SScan --> SLZ4["LZ4 In-RAM Compression"] SLZ4 --> SRetain["🛡️ Up to 4.2x Retention (Zero Drop Loss)"] end

• Snapshot SPDO2 vs Generic Memory Snapshot


• NVMe (Non-Volatile Memory Express) vs SATA SSD vs HDD

- NVMe : PCIe-attached flash storage protocol supporting up to 64,000 command queues of 64k entries each, with ultra-low latency of 10 to 30 µs.

- SATA SSD (AHCI) : Legacy protocol designed for spinning disks, limited to 1 command queue of 32 entries (latencies 100-500 µs).

- HDD (Mechanical Disks) : Physical rotating platters, 5 to 15 ms latency (500x slower than NVMe), limited to 100-200 IOPS.


• IOPS (Input/Output Operations Per Second) & Throughput (MB/s)

- IOPS : Number of distinct read/write storage operations per second (critical for small random WAL appends and fsync operations).

- Throughput (MB/s) : Total byte volume transferred per second (critical for bulk snapshot creation and recovery).


• Linux Kernel Page Cache & Direct I/O (O_DIRECT) vs Buffered I/O

- Buffered I/O (Default) : File writes enter kernel RAM buffers (Page Cache). Syscall write() returns in ~1 µs, but data is not yet committed to physical flash media.

- Direct I/O (O_DIRECT) : Bypasses kernel Page Cache and writes directly from user-space buffers to hardware controllers.

- fsync() : Forces kernel to flush dirty Page Cache blocks to physical storage media before returning success.


8. Persistence, Recovery & HA Boundaries

• Durability, ACK and Local Volume


• WAL, AOF, Sequence and Watermark


• fsync, WAL Modes and Atomic Commit


• SAVE, SAVE WAIT and PERSIST.STATUS


• Recovery, Integrity and Failure Testing


• HA, RPO/RTO and Non-Existent Features


• P0 to P3 Milestones of the Snapshot Plan

In PLAN_SNAPSHOT_FIABILITE.md, P0 designates observable persistence status, P1 verified SPDO2 snapshots, P2 crash tests and operations, and P3 single-node WAL logging. These represent single-node durability milestones, not an HA roadmap.


9. Data Structures & Memory Allocation

• CPU Cache Hierarchy (L1, L2, L3) & Cache Lines (64 bytes)

- CPU Registers : ~0.3 ns (immediate ALU access).

- L1 Cache (Data/Instruction) : ~0.9 ns (32 to 64 KB per core).

- L2 Cache : ~2.8 ns (512 KB to 1 MB per core).

- L3 Cache (Shared) : ~11 to 15 ns (16 to 128 MB shared across all cores).

- Main DRAM : ~60 to 100 ns (100x slower than L1 cache).


• Pointer Chasing & Cache Miss vs Contiguous Memory

- Pointer Chasing : Traversing fragmented pointer structures (linked lists, sparse trees). Jumping to unpredictable memory addresses causes L1/L2 Cache Misses, stalling the CPU pipeline for ~200 clock cycles while awaiting DRAM.

- Contiguous Memory (Flat Arrays / Slices) : Storing data in flat vectors (Vec<f32>, Bytes). The CPU Hardware Prefetcher streams subsequent elements into L1 cache before they are requested.


• Latency Percentiles (P50, P90, P99, P99.9) & Jitter

- P50 (Median) : 50% of requests complete faster than this threshold.

- P90 / P95 : Reflects performance experienced by the majority of requests.

- P99 / P99.9 (Tail Latency) : Maximum latency experienced by the slowest 1% or 0.1% of requests.

- Jitter : Latency variability caused by Garbage Collection pauses or lock contention.


• Backpressure & Flow Control


10. Python SDK, Synchronization & Data Models

• SpedoClient, SpedoDict, SpedoList and @spedo_model


• auto_sync(globals()), Globals and Claim-Check Pattern


11. Abbreviations, Variables and Conventions

TermShort Definition
ACKAcknowledgment confirming command processing.
AOFRedis Append-Only File format (distinct from Spedo binary WAL).
APIApplication Programming Interface.
ArrowApache Arrow: In-memory columnar format for analytics and AI.
CASCompare-And-Swap: Hardware atomic CPU instruction.
CDCChange Data Capture: Real-time data mutation stream.
COLCost Of Life: Memory pressure supervisor adjusting long TTLs.
CoWCopy-on-Write memory mechanism.
CRC-32CHardware-accelerated Castagnoli CRC checksum for data integrity.
Direct I/OStorage I/O bypassing operating system Page Cache (O_DIRECT).
EIOOperating system I/O error.
ENOSPCOperating system error indicating storage volume is full.
FMAFused Multiply-Add: Computes $a · b + c$ in a single CPU cycle.
GEMMGeneral Matrix Multiply: Fundamental linear algebra operation in LLMs.
GILCPython Global Interpreter Lock.
HAHigh Availability: Cluster replication and failover (single-node Spedo is not HA).
I/OInput/Output operations across network and disk.
IOPSInput/Output Operations Per Second.
In-SituComputation executed directly inside database RAM without network transfer.
JSONJavaScript Object Notation. RFC 7396 (Merge Patch) natively supported.
KVKey-Value pairs in primary keyspace.
L1 / L2 / L3CPU hardware cache tiers (0.9 to 15 ns vs 100 ns in DRAM).
LRULeast Recently Used eviction policy.
LZ4High-speed lossless compression algorithm (> 4 GB/s).
NVMeNon-Volatile Memory Express: High-performance flash storage protocol.
OOMOut Of Memory condition.
P0–P3Milestones of the single-node persistence plan.
POSIXOperating system standards defining atomic rename and fsync semantics.
PVCKubernetes PersistentVolumeClaim.
RAMRandom Access Memory (volatile primary storage).
RDBRedis point-in-time snapshot format (distinct from Spedo SPDO2).
RESP2 / RESP3REdis Serialization Protocol v2 and v3.
RPORecovery Point Objective: Maximum allowable data loss window.
RTORecovery Time Objective: Target service restoration time.
SDKSoftware Development Kit.
SIMDSingle Instruction, Multiple Data: CPU vector instructions (AVX2/AVX-512/NEON).
SPDO1 / SPDO2Spedo snapshot format identifiers (SPDO2 is current standard).
SPWL1Spedo binary Write-Ahead Log format identifier.
TCPTransmission Control Protocol.
TTLTime To Live expiration duration.
WALWrite-Ahead Log written prior to issuing durable write ACKs.
Variable / CommandRole
SPEDO_PERSIST_PATHStorage path for checkpoints; if unset, persistence and WAL are disabled.
SPEDO_SNAPSHOT_INTERVAL_SECSPeriodic checkpoint interval in seconds (0 disables timer).
SPEDO_WAL_FSYNCdisabled, always, everysec, or none; defines WAL durability contract.
SPEDO_ADAPTIVE_LEASE_MODEdisabled (default) or observe; observe samples workload/lease telemetry but does not route requests.
SPEDO_RECOVERY_POLICYfail or empty_on_invalid behavior upon invalid persistence files.
SAVETriggers asynchronous background checkpoint.
SAVE WAITBlocks until checkpoint commit is confirmed on disk.
PERSIST.STATUSReturns detailed operational status of checkpoint and WAL subsystems.
WF.STATUS_BATCHNative command returning status and metadata for multiple workflow documents in a single round-trip.
WF.COUNT_DONENative $O(1)$ command returning [done_count, total_count] for instantaneous workflow batch completion checks.

12. Executive Summary for Technical Audits & Engineering Due Diligence

When communicating technical architecture with engineering leads, principal architects, or auditors:

1. Concurrency : « Spedo leverages SO_REUSEPORT and a 64-partition sharded memory architecture; throughput figures vary by workload and are documented in PERFORMANCE.md. »

2. Client & Networking : « spedo_core accelerates the Python SDK and releases the GIL during network I/O; local L1 hits or write-behind queues have different operational semantics than confirmed server ACKs. »

3. Durability : « KV/JSON mutations achieve synchronous local durability only when SPEDO_PERSIST_PATH is configured with SPEDO_WAL_FSYNC=always. Single-node SPDO2 snapshots and WAL logs do not constitute remote offsite backups or distributed HA. »

4. Memory & Reactivity : « COL, in-RAM compression, and SPEDO.WATCH are high-performance memory and synchronization primitives; they do not replace distributed multi-datacenter consensus or durable streaming brokers. »


Spedo — Technical & Architectural Reference Lexicon v0.64.0