bluegreencity-ki

ADR-002: Spatial Database Technology Evaluation (SedonaDB and DuckDB)

Status

Accepted (2025-11) - Recommending evaluation of SedonaDB (spatial-optimized) and/or DuckDB (general analytics) as complementary embedded analytics databases

Current state (Oct 2026): not implemented. No DuckDB/SedonaDB component was ever integrated (no dependency, no module), and the planned review (2026-05-15) did not change anything. PostGIS remains the sole database. This ADR is retained as a dated evaluation record, not as an active decision.

Context

BlueGreenCity-KI currently uses PostGIS as the primary geodatabase for multi-user access and persistent storage, with GeoPandas for in-memory processing. As the project scales and analytical demands increase, we evaluated two additional embedded database technologies to complement our existing stack:

  1. SedonaDB - Lightweight embedded spatial database (single-machine, no Spark required)
  2. DuckDB - Embedded analytical database with spatial extension

Important Clarification: SedonaDB is a standalone lightweight spatial database that runs on single computers. It does NOT require Apache Spark infrastructure. Apache Sedona is a separate distributed framework built on Spark that SedonaDB can optionally migrate to if extreme scale (>100GB) is needed.

Current Challenges

Performance Bottlenecks:

Developer Experience:

Future Scale Concerns:

Current Scale

Dataset Sizes:

Projected Growth:

Forces at Play

Technical Forces:

Business Forces:

Team Forces:

Technology Evaluation

We evaluated three scenarios:

  1. Status Quo: PostGIS + GeoPandas only
  2. SedonaDB Integration: Add SedonaDB for spatial analytics (embedded, no Spark)
  3. DuckDB Integration: Add DuckDB for general analytical workloads

Performance Benchmark Summary (from forrest.nyc analysis):

Operation PostGIS DuckDB SedonaDB Best For
Aggregations 22s 3s 8s DuckDB (7x faster)
Load 1M points 45s 8s 12s DuckDB (5x faster)
Spatial joins (1M) 180s 42s 35s SedonaDB (5x faster)
Range queries 5s 2s 4s DuckDB (2.5x faster)
Complex spatial joins 320s 98s 45s SedonaDB (7x faster)

Key Insights:

Decision

We will adopt a hybrid multi-database architecture with PostGIS as the foundation and SedonaDB/DuckDB as complementary embedded analytical engines:

Short-Term (Immediate): Integrate SedonaDB and/or DuckDB

Decision: Evaluate both embedded databases - choose based on workload

SedonaDB - For spatial-heavy analytics:

DuckDB - For general analytics:

Implementation:

  1. Add SedonaDB and/or DuckDB to environment.yml dependencies
  2. Create utility modules: bluegreencity_ki/io/sedonadb_utils.py and/or duckdb_utils.py
  3. Implement PostGIS → GeoParquet export pipeline
  4. Document hybrid workflow (PostGIS for production, SedonaDB/DuckDB for analytics)
  5. Provide example notebooks and query templates

Use Cases:

Architecture:

PostGIS (production)
    ↓ export to GeoParquet
SedonaDB (spatial) or DuckDB (general) ←→ Fast analytics
    ↓ results
GeoPandas ←→ BlueGreenCity-KI Pipeline

Long-Term: Apache Sedona (If Needed)

What: Only consider distributed Apache Sedona if dataset grows to extreme scale

Trigger Conditions:

Evaluation Criteria:

Decision Point: Re-evaluate in 6-12 months based on actual scale and requirements

Long-Term: Database Usage Guidelines

Use PostGIS when:

Use DuckDB when:

Use SedonaDB when (future):

Use GeoPandas when:

Consequences

Positive Consequences

Performance Improvements:

Developer Experience:

Scalability & Future-Proofing:

Operational Benefits:

Negative Consequences

Complexity:

Limitations:

Migration Risks:

Neutral Consequences

Architectural Changes:

Operational Changes:

Alternatives Considered

Alternative 1: PostGIS Only (Status Quo)

Description: Continue using PostGIS as sole database, optimize queries and indexes

Pros:

Cons:

Reason for rejection:

Alternative 2: DuckDB Only (Replace PostGIS)

Description: Migrate entirely to DuckDB, eliminate PostGIS

Pros:

Cons:

Reason for rejection:

Alternative 3: Apache Sedona Only (Distributed Spark-Based)

Description: Skip SedonaDB and go directly to distributed Apache Sedona (Spark-based) for all spatial processing

Pros:

Cons:

Reason for rejection:

Alternative 4: Cloud Data Warehouse (BigQuery GIS, AWS Redshift Spatial)

Description: Use managed cloud data warehouse with spatial extensions

Pros:

Cons:

Reason for rejection:

Alternative 5: DuckDB + SedonaDB (No PostGIS)

Description: Replace PostGIS entirely with DuckDB (analytics) + SedonaDB (scale)

Pros:

Cons:

Reason for rejection:

Implementation Plan

Phase 1: DuckDB Integration (Weeks 1-4)

Week 1-2: Setup and Foundation

Week 3-4: Export Pipeline and Documentation

Phase 2: Integration and Testing (Weeks 5-8)

Week 5-6: Query Templates and Utilities

Week 7-8: Benchmarking and Optimization

Phase 3: Team Adoption (Weeks 9-12)

Week 9-10: Training and Documentation

Week 11-12: Production Integration

Phase 4: Long-Term Monitoring (Months 3-12)

Success Metrics

Performance:

Developer Experience:

Adoption:

References

Performance Analysis

SedonaDB Documentation

DuckDB Documentation

Internal Documentation


Date: 2025-11-15
Author: @wanderfunke (with GitHub Copilot assistance)
Reviewers: Pending team review
Status: Accepted for DuckDB integration, SedonaDB evaluation deferred — never executed (see Status section, Oct 2026 note)
Next Review: 2026-05-15 (6 months) or when dataset size >10GB — passed without action