Stateless, horizontally autoscaling Python 3.12+ Apache Arrow Flight microservice executing sandboxed DuckDB analytical queries over content-addressed Parquet artifacts.
See architecture.md for the full 5-layer backend architecture, memory partitioning blueprint, and Architecture Decision Records (ADR-001–ADR-005).
- Apache Arrow Flight IPC & HTTP Ops Server (
internal/flight/,api/):TabularFlightServer(pyarrow.flight.FlightServerBase, port8815) handlingDoGet(Ticket)analytical queries andDoAction(Action)(cache_warm,health_check), streaming zero-copy ArrowRecordBatchframes over HTTP/2 gRPC.OpsHTTPServer(port8080) exposing/healthz,/ready,/metrics,/openapi.yaml, and/docs(Swagger UI), with gracefulSIGTERM/SIGINTdraining.
- Deterministic SQL AST Security Validator (
internal/validator/):sqlglotAST whitelisting (<= 2 mswarm steady-state) permitting only read-onlySELECT,WITH(CTEs),UNION/INTERSECT/EXCEPT, andSubqueryconstructs.- Strict allowlist for SQL functions, join count limits (
MAX_JOINS=5), and query length limits (MAX_SQL_LENGTH=8192). - Blocks DML/DDL,
PRAGMA,SET,RESET,SUMMARIZE,DESCRIBE,SHOW,PIVOT,COPY,ATTACH,DETACH,LOAD,INSTALL, and DuckDB filesystem/network functions.
- Tier-1 Disk-Backed NVMe Cache & S3 Range-Read Hydration (
internal/storage/):- Content-addressed local cache (
<CACHE_DIR>/{s3_bucket}/{tenant_id}/{table_hash}.parquet,10 GiBceiling) with single-flight download coalescing, atomicos.replacewrites, lock-free concurrent readers, and in-memory LRU eviction. - Async
aiobotocoreS3 range-read streaming (8 MiBchunks) over internal VPC endpoints without monolithic Python heap buffering. TableResolverenforcesS3_BUCKET_ALLOWLISTand canonicals3_key == artifacts/{tenant_id}/{table_hash}.parquettenant isolation.
- Content-addressed local cache (
- Ephemeral DuckDB Sandbox Runtime (
internal/sandbox/):apply_sandbox_lock(internal/sandbox/security_profile.py) opensduckdb.connect(":memory:"), configurestemp_directory = '', per-workermemory_limit(floor(2.5 GiB / POOL_SIZE)inMiB, e.g.,640MiBatPOOL_SIZE=4), andthreads = 2, materializes only the single validated{hash}.parquetartifact as a temp table (CREATE TEMP TABLE "<table_alias>" AS SELECT * FROM read_parquet(...)), and immediately locksenable_external_access = falseandlock_configuration = true.- Streams chunked PyArrow
RecordBatchframes viaRecordBatchReaderwithoutfetch_arrow_table()full materialization.
- Disposable Subprocess Pool & Circuit Breaker (
internal/pool/):pebble.ProcessPoolsupervisor (max_workers=POOL_SIZE,max_tasks=100) streaming Arrow IPCRecordBatchchunks over an OS pipe /multiprocessing.connection.- Per-worker
5shard execution deadline with isolated child termination (SIGKILLon POSIX /TerminateProcesson Windows) and automatic worker replacement (ADR-001).
- Observability, Secured Logging & KEDA Autoscaling (
internal/telemetry/,deployments/):- Structured JSON logs with redaction of authorization headers, bearer tokens, AWS credentials, presigned S3 query parameters (
X-Amz-Signature,X-Amz-Credential,X-Amz-Security-Token), and sensitive literals. - Prometheus metrics (
tabular_worker_active_queries,tabular_worker_query_duration_seconds,tabular_worker_cache_hit_ratio,tabular_worker_subprocess_recycles_total,tabular_worker_flight_stream_bytes_total,tabular_worker_ast_rejections_total), OpenTelemetry tracing, and KEDAScaledObject(4..24replicas).
- Structured JSON logs with redaction of authorization headers, bearer tokens, AWS credentials, presigned S3 query parameters (
python -m venv .venv
# Linux/macOS:
source .venv/bin/activate
# Windows PowerShell:
.venv\Scripts\Activate.ps1
pip install -e ".[dev,test]"
cp .env.example .envBefore starting the daemon locally, edit .env:
- S3 bucket allowlist & access: Add your bucket(s) to
TABULAR_WORKER_S3_BUCKET_ALLOWLIST(e.g.,["my-tabular-bucket"]) and configureTABULAR_WORKER_S3_ENDPOINT_URL/TABULAR_WORKER_S3_REGIONas needed.TableResolverfails closed and rejects all buckets whenTABULAR_WORKER_S3_BUCKET_ALLOWLISTis empty. Note thatSettingsignores non-TABULAR_WORKER_keys in.envand does not populateos.environ, so configure AWS credentials via an AWS profile or exportAWS_ACCESS_KEY_ID/AWS_SECRET_ACCESS_KEY(andAWS_SESSION_TOKENif applicable) in your shell soS3Streamer'saiobotocoreprovider chain can use them. - Writable cache directory: Set
TABULAR_WORKER_CACHE_DIRto a writable local path (e.g.,./.cache/tabular-worker), or create/var/cache/tabular-workerand grant write permissions to the user running the daemon before startup.
Start the worker daemon locally:
python -m cmd.worker.mainThe Arrow Flight gRPC server listens on 0.0.0.0:8815 and the HTTP Ops server listens on 0.0.0.0:8080 (/docs for Swagger UI, /metrics for Prometheus).
All runtime settings are 12-factor environment variables prefixed with TABULAR_WORKER_ (defined in internal/config/settings.py and documented in .env.example):
| Variable | Default | Description |
|---|---|---|
TABULAR_WORKER_POOL_SIZE |
4 |
Number of disposable DuckDB worker subprocesses |
TABULAR_WORKER_MAX_TASKS_PER_CHILD |
100 |
Tasks before a worker subprocess is recycled |
TABULAR_WORKER_QUERY_TIMEOUT_SECONDS |
5.0 |
Hard per-query subprocess circuit breaker timeout |
TABULAR_WORKER_DUCKDB_TOTAL_MEMORY_BYTES |
2684354560 |
Aggregate DuckDB memory ceiling (2.5 GiB across pool) |
TABULAR_WORKER_CACHE_DIR |
/var/cache/tabular-worker |
Tier-1 NVMe Parquet cache directory |
TABULAR_WORKER_CACHE_MAX_BYTES |
10737418240 |
Tier-1 cache LRU capacity (10 GiB) |
TABULAR_WORKER_S3_BUCKET_ALLOWLIST |
[] |
Allowed S3 buckets (JSON array or comma-separated) |
TABULAR_WORKER_MAX_CONCURRENT_QUERIES |
4 |
Bounded in-flight query semaphore (RESOURCE_EXHAUSTED above cap) |
TABULAR_WORKER_OTEL_ENABLED |
false |
Enable OpenTelemetry OTLP gRPC span export |
Note
.env is for local development only. Production Helm defaults in deployments/helm/values.yaml are synced from .env.prod via python scripts/sync_env_to_deployments.py --sync. See deployments/SECRET_MANAGEMENT.md for secret injection guidelines.
Run individual checks or the full Makefile gate (make check):
ruff check .
ruff format --check .
mypy cmd internal api
bandit -r cmd internal api -ll
pip-audit
pytest -v test/unit test/security test/chaos test/integrationThe default test/chaos suite runs a fast 500-stream bounded concurrency soak and burst backpressure test. To run the opt-in 8-hour jemalloc and P95 <= 45ms endurance suite:
RUN_SOAK_TESTS=1 pytest -v -m soak test/chaosdocker build -f deployments/docker/Dockerfile -t rag-tabular-analytics-worker:0.1.0 .
docker run --rm -p 8815:8815 -p 8080:8080 --read-only \
-e TABULAR_WORKER_CACHE_MAX_BYTES=805306368 \
--tmpfs /var/cache/tabular-worker:rw,noexec,nosuid,uid=10001,gid=10001,size=1g \
--tmpfs /tmp:rw,size=256m \
rag-tabular-analytics-worker:0.1.0- Staging:
deployments/helm/values-staging.yamlanddeployments/argocd/application-staging.yaml - Production:
deployments/helm/values-prod.yaml,deployments/argocd/application-prod.yaml, anddeployments/argocd/rollout-canary.yaml(10% -> 25% -> 50% -> 100%gated byAnalysisTemplateover Prometheus SLIs)
helm lint deployments/helm
helm template rag-tabular-analytics-worker deployments/helm -f deployments/helm/values-prod.yaml > /dev/nullarchitecture.md— 5-layer backend architecture, request flow, memory partitioning, ADRs, and repository layout.ai/doc-api.md— Authoritative HTTP Ops, Arrow Flight IPC (DoGet/DoAction), and Prometheus metric contractsapi/openapi/openapi.yaml— OpenAPI 3.1 specification for the HTTP Ops server.ai/security.md— Threat model, DuckDB sandbox locks, and secured logging invariants.ai/progress-tracker.md— Implementation phases, ADRs, and operational runbooks