---
title: "Deploy duckdb-railway"
description: "Host DuckDB as a secure SQL REST API on Railway🪿"
category: "Analytics"
url: https://railway.com/deploy/duckdb-railway
---

# Deploy duckdb-railway

Host DuckDB as a secure SQL REST API on Railway🪿

**[Deploy duckdb-railway on Railway](https://railway.com/template/duckdb-railway)**

- **Creator:** Lonely Wolf
- **Category:** Analytics

## Template content

### duckdb https://avatars.githubusercontent.com/u/82039556?s=60&v=4

- **Source:** https://github.com/8u9i/duckdb-railway
- **Start command:** `uvicorn main:app --host 0.0.0.0 --port 8080`
- **Health check:** /health
- **Public domain:** Yes

## Documentation

# Deploy and Host DuckDB on Railway

DuckDB is a fast, in-process analytical SQL database for running complex queries over large datasets without a separate server. This template hosts it as a persistent, authenticated HTTP query service on Railway — a ready-to-use REST API backed by a DuckDB file on a volume, so your data survives redeploys and stays secure by default.

## About Hosting DuckDB

DuckDB normally runs embedded inside your application — there's no server to connect to. This template wraps it in a small FastAPI service exposing a `/query` REST endpoint, giving you a hosted DuckDB you can call over HTTP from any client. A Railway volume mounted at `/data` stores the database file, so tables and data persist across deployments. Requests require an auto-generated API key, and the database is read-only by default unless you set `DUCKDB_ALLOW_WRITE=true`. It's a lightweight way to get an always-on analytical SQL endpoint for dashboards, analytics backends, and data APIs — without running or managing database infrastructure yourself.

## Common Use Cases

- **Power live dashboards instantly** — point Looker, Metabase, Grafana, or a custom frontend straight at the `/query` endpoint and get sub-second analytical queries without standing up a warehouse
- **Skip the database ops entirely** — get a persistent, always-on SQL backend for internal tools and apps in minutes, with none of the setup, patching, or scaling headaches of Postgres or a full data warehouse
- **Query CSV/Parquet files like a pro analyst** — drop datasets on the volume and run DuckDB's rich, fast SQL dialect over them directly, no ETL pipeline required
- **Prototype OLAP workloads for free-ish** — spin up a real analytical database in seconds to test ideas, validate a data model, or demo a feature, then throw it away or scale it up

## Dependencies for DuckDB Hosting

- **DuckDB** — in-process analytical SQL engine
- **FastAPI + Uvicorn** — REST framework and ASGI server
- **Railway Volume** — persistent storage mounted at `/data`

### Implementation Details

The service exposes `POST /query` (JSON body: `{"sql": "SELECT 42"}`) and `GET /query?sql=...`, returning `columns`, `rows`, `row_count`, and `elapsed_ms`. Healthcheck available at `/health`. Writes are disabled unless `DUCKDB_ALLOW_WRITE=true`.

## Why Deploy DuckDB on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway hosts your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying DuckDB on Railway, you're one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more — all on Railway.

## Similar templates

- [Betterlytics](https://railway.com/deploy/betterlytics) — Betterlytics is a cookieless analytics platform GDPR-compliant.
- [Finance Tracker](https://railway.com/deploy/finance-tracker-1) — Private multi-user household finance ledger with budgets and CSV import.
- [Matomo Analytics + MariaDB](https://railway.com/deploy/matomo-analytics-mariadb) — Privacy-friendly analytics with MariaDB and persistent volumes.

Open this page in a browser: https://railway.com/deploy/duckdb-railway
