Database Comparison

MongoDB vs DuckDB vs Redis for NGSI-LD

Overview Comparison

AspectMongoDBDuckDBRedis
TypeDocument store (NoSQL)Analytical RDBMS (OLAP)In-memory key-value store
Data ModelJSON/BSON documentsColumnar relational tablesKey-value, hashes, sets, sorted sets
Query LanguageMQLSQL (PostgreSQL dialect)Commands + RediSearch
ArchitectureClient-serverEmbedded (in-process, like SQLite)Client-server
StorageRow-oriented on disk (BSON)Columnar on diskIn-memory (optional persistence)
Best ForOLTP, flexible schemasOLAP, analytics, batchCaching, ultra-low-latency CRUD
ConcurrencyMulti-user, multi-connectionSingle-writer, multi-readerSingle-threaded event loop
ScalingHorizontal (sharding)Vertical onlyHorizontal (Redis Cluster)
TransactionsMulti-document ACIDFull ACIDMULTI/EXEC (limited)
JoinsLimited ($lookup)Full SQL joinsNone
MemoryConfigurable cacheStreams from diskAll data must fit in RAM
Footprint~500MB+~20MB library~10MB binary
LicenseSSPLMITRSALv2 + SSPLv1

When to Use Each

MongoDB

  • Operational/transactional workloads (high-throughput R/W)
  • Flexible, evolving schemas
  • Real-time applications with low-latency CRUD
  • Horizontal scaling beyond a single machine
  • Geospatial queries (built-in geo indexes)
  • Multi-user concurrent access

DuckDB

  • Analytical queries (aggregations, joins, window functions)
  • Embedded analytics — no separate server
  • ETL / data transformation (Parquet, CSV, SQL)
  • Single-machine analytics on billions of rows
  • Zero configuration, just link the library
  • Cost-sensitive — no server infrastructure

Redis

  • Ultra-low-latency CRUD — sub-millisecond reads/writes
  • Caching layer for frequently accessed data
  • Pub/Sub and event-driven architectures
  • Session / state management
  • Rate limiting, counters, leaderboards (atomic operations)

Performance Characteristics

WorkloadMongoDBDuckDBRedis
Point lookups by keyFast (indexed)AcceptableFastest (sub-ms)
Insert single recordsFastAcceptableFastest (sub-ms)
Bulk insertsGoodVery fastFast (pipelining)
Full table scansSlowVery fast (columnar)Impractical at scale
Complex aggregationsModerateVery fastVery limited
JoinsSlow ($lookup)Very fastNot supported
Concurrent writersExcellentSingle writerSingle-threaded but fast
Geo queriesGood (2dsphere)LimitedGood (GEOSEARCH)
Complex filtered queriesGoodVery fastLimited (needs RediSearch)

Redis as a MongoDB Replacement for Current State?

Where Redis Wins

  • Raw speed — 10–100x faster than MongoDB for simple key-based CRUD
  • Simpler operations — no query planner overhead, no disk I/O for reads
  • Built-in pub/sub — natural fit for NGSI-LD notification triggering
  • Geo queries — GEOSEARCH supports radius and bounding box natively
  • Lower operational overhead — simpler to run than MongoDB

Where Redis Falls Short

  • RAM cost — millions of entities with rich JSON-LD gets expensive
  • Complex NGSI-LD queries — the q parameter's nested attribute filters are hard to map
  • No native joins — cross-entity-type queries need application logic
  • Persistence — RDB/AOF not as robust as MongoDB's journaling
  • Transactions — MULTI/EXEC is not full ACID

Key Tradeoffs

Recommendation for the FiWorks NGSI-LD Broker

RoleBest CandidateRationale
Current state (simple access)RedisFastest CRUD by entity ID
Current state (complex queries)MongoDBRich query engine for q filters
Current state (hybrid)Redis + MongoDB/DuckDBSpeed + query power + durability
Temporal / TRoEDuckDB or TimescaleDBAnalytical queries over time-series data

Verdict: Hybrid Architecture

The ideal FiWorks NGSI-LD Broker database architecture is not a single technology choice but a layered approach:

  • Redis as the hot cache for current entity state — sub-millisecond GET/PATCH by entity ID, built-in pub/sub for notification triggering
  • DuckDB (embedded) for complex queries and temporal data — full SQL power without a separate server process
  • Optional MongoDB for deployments needing horizontal scaling, durability guarantees, or rich q-filter support beyond what Redis offers

DuckDB's embedded nature (in-process, like SQLite) is particularly interesting — it eliminates the network roundtrip to a database server entirely, which aligns perfectly with the C broker's performance-first philosophy.