Skip to main content

Concurrent Access & Scaling

Multi-node HA and horizontal scaling planned for Pixeltable Cloud (2026).

Web Framework Concurrency

For standard insert, query, and delete endpoints, consider built-in HTTP serving with FastAPIRouter or a TOML config before writing custom endpoint handlers. It handles request/response schemas, media serving, and background jobs automatically.
Pixeltable is thread-safe and works with FastAPI, Flask, Django, and other web frameworks out of the box. The key rule: use sync (def) endpoint handlers, not async def.

Why Sync Endpoints

FastAPI (and Starlette) dispatches sync (def) handlers to a thread pool. Each concurrent request gets its own thread, and Pixeltable automatically creates an isolated database connection per thread. This gives you true parallel request handling with no extra configuration.
Do not use async def for endpoints that call Pixeltable. Pixeltable’s API is synchronous. Inside an async def handler, Pixeltable calls block the event loop, serializing all requests and starving other coroutines. With def handlers, FastAPI’s thread pool handles concurrency for you.

Returning Query Results

table.select(...).collect() returns a ResultSet object, which Pydantic cannot serialize directly. You have two options: Option 1: to_pydantic() (recommended for FastAPI) Define a Pydantic model and let Pixeltable validate and convert each row. FastAPI serializes these natively.
Option 2: to_pandas() + to_dict() Convert via pandas when you don’t need a Pydantic model.

uvloop Compatibility

Pixeltable is compatible with uvloop, the high-performance event loop used by default in many production deployments. No special configuration is needed — sync endpoints work identically whether the server uses the default asyncio loop or uvloop.

GPU Acceleration

  • Automatic GPU Detection: Pixeltable uses CUDA GPUs for local models (Hugging Face, Ollama) when available.
  • CPU Fallback: Models run on CPU if no GPU detected (functional but slower).
  • Configuration: Control via CUDA_VISIBLE_DEVICES environment variable.

Error Handling

Access error details via table.column.errortype and table.column.errormsg.

Testing Transformations Before Deployment

When you add a computed column, Pixeltable executes it immediately for all existing rows. For expensive operations (LLM calls, model inference), validate your logic on a sample first using select(); nothing is stored until you commit with add_computed_column().
This “iterate-then-add” workflow lets you catch errors early without wasting API calls or compute on your full dataset.
Pro tip: Save expressions as variables to guarantee identical logic in both steps:

Full Tutorial

Step-by-step guide with examples for built-in functions, expressions, and custom UDFs

Schema Evolution

Production Safety:
  • Version control schema.py like database migration scripts.
  • Rollback via table.revert() (single operation) or Git revert (complex changes).

Updating Models

The most common schema evolution is switching an embedding or LLM model. In a traditional stack this requires a migration script, a compute cluster, reprocessing every row, and a maintenance window. In Pixeltable it’s one line — the old column keeps working while the new one backfills. Traditional approach:
Pixeltable approach:
Because both columns coexist, you can A/B test retrieval quality before cutting over — no rollback plan needed.

Deployment Patterns

Web Applications:
  • For standard endpoints, use pxt serve with a TOML config or FastAPIRouter
  • Run python schema.py once before starting workers to create tables
  • Each router calls pxt.get_table() directly and defines its own @pxt.query functions
  • Use sync (def) endpoint handlers for concurrent request support

Pixeltable Starter Kit

Clone a production-ready FastAPI + React app with multimodal upload, search, and agent endpoints — plus deployment configs for Docker Compose, Helm, Terraform, and AWS CDK.
Batch Processing:
  • Schedule via cron, Airflow, AWS EventBridge, GCP Cloud Scheduler, or webhooks
  • Deploy to Cloud Run Jobs, Lambda, ECS Fargate, Kubernetes Jobs
  • Isolate batch workloads from real-time serving (separate containers/instances)
  • Use Pixeltable’s incremental computation to process only new data
  • The starter kit includes a batch processing pipeline with export_sql and the destination parameter, plus ready-to-use deploy configs for Lambda, Cloud Run, ECS Fargate, and K8s Jobs
Containers:
  • Docker provides reproducible builds across environments
  • Full Backend: Mount persistent volume at ~/.pixeltable (or set PIXELTABLE_HOME)
  • Kubernetes: Use ReadWriteOnce PVC (single-pod write access)
  • Docker Compose or Kubernetes for multi-container deployments
  • The starter kit includes a multi-stage Dockerfile and ready-to-use deployment configs:

Environment Management

Multi-Tenancy and Isolation

Logical Isolation Example:

High Availability Constraints

Single-Writer Limitation: Pixeltable’s storage layer uses an embedded PostgreSQL instance. Only one process can write to ~/.pixeltable/pgdata at a time.

Troubleshooting

Reset Database (Development Only)

To completely reset Pixeltable’s local state during development:
This deletes all data. Only use in development. For production, use backups and table.revert() or snapshots instead.

Common Issues

Environment Separation

Use environment-specific namespaces to manage dev/staging/prod configurations:

Testing

Staging Environment:
  • Mirror production configuration.
  • Test schema changes, UDF updates, application code changes.
  • Use representative data (anonymized or synthetic).
Last modified on June 24, 2026