Database, cache and auth for a vibe-coded app on Railway
Short answer: for most apps built with an AI frontend tool, start with one PostgreSQL service and connect to it over Railway’s private network. Tracklayer’s PostgreSQL 18 with pgvector template adds connection pooling and daily backups to a bucket, and it works as a plain Postgres even if you never use vectors. Add a cache (Redis or Valkey), an auth server (Keycloak) or a backup manager (Databasus) only when you have a reason.
Deploy Postgres 18 with pgvector on RailwayWhat a frontend tool does not give you
AI tools such as Lovable, Bolt, v0 and Cursor are good at screens. A real product also needs somewhere to keep data, optionally a fast key-value store, and a way to log users in. On Railway each of these is a service in the same project, and your app reaches them by reference variables instead of copied passwords.
Pick the database
Three questions settle most choices. Is your data tables or documents? Do you need maps or vector search? Do you need to recover to an exact minute?
| Pick this if | Template |
|---|---|
| You want a general Postgres, with or without embeddings, plus pooling and daily backups | Postgres 18 with pgvector |
| You need to restore to a chosen point in time, not just the last nightly dump | PostgreSQL 18 with point-in-time recovery |
| Your app stores locations and runs distance or area queries | PostGIS 3.6 spatial database |
| Your code or Prisma schema expects MongoDB, with transactions or change streams | MongoDB 8 replica set |
| Your app was written for MySQL and you want an open-source database with phpMyAdmin | MariaDB 12.3 LTS |
Pick a cache, auth server or backup tool
| Pick this if | Template |
|---|---|
| You need caching, queues or counters and want Redis 8 with the RedisInsight web UI | Redis 8 with RedisInsight |
| You want a BSD-licensed drop-in for Redis, with JSON, Bloom and Search modules | Valkey 9 |
| You need single sign-on, OpenID Connect, SAML or social login you run yourself | Keycloak 26 |
| You want scheduled backups of existing Postgres, MySQL, MariaDB or MongoDB databases with a dashboard | Databasus |
What people deploy for Postgres on Railway
| Template | Creator | Deployments | Services |
|---|---|---|---|
| PostgreSQL | Railway Templates | 394,257 | 1 |
| n8n | Thalles Passos's Projects | 5,850 | 2 |
| Langflow | – | 2,852 | 2 |
| pgvector | Brody's Projects | 2,077 | 1 |
| PostGIS | Railway Templates | 1,505 | 1 |
| n8n | Bruno's Team | 1,293 | 2 |
| ExpressJS PostgreSQL | opqr's Projects | 1,101 | 2 |
| medusajs ecommerce Nextjs, Postgres, Redis | Rasmus Puls's Projects | 1,036 | 4 |
Railway marketplace data as of 2026-11-19. Full ranking: Best PostgreSQL templates on Railway.
Deploy Postgres and connect your app
These steps use Tracklayer’s Postgres 18 with pgvector template (PostgreSQL 18, pgvector 0.8, PgBouncer 1.26.1).
- Deploy the template. It creates Postgres with a volume, PgBouncer, a daily backup job and a Railway Bucket. Credentials are generated at deploy and shown in the Postgres service’s Variables.
- Check that it works. Copy
DATABASE_PUBLIC_URL, add?sslmode=require(the certificate is self-signed) and connect withpsql.SELECT extversion FROM pg_extension WHERE extname = 'vector';confirms pgvector. - Create a role for your app. The template’s own advice is to use a dedicated role instead of the
postgressuperuser. - Point your app at it. In the app service, reference
DATABASE_POOL_URLfor normal queries. It goes through PgBouncer on the private network. UseDATABASE_URL, the direct private connection, for migrations, index builds andLISTEN/NOTIFY. Prisma needs?pgbouncer=trueon the pooled URL. - Go private-only if you can. If only Railway services connect, remove the TCP proxy under Settings, Networking.
The variable names match Railway’s own Postgres, so references written as ${{Postgres.*}} keep working. For the other databases the connection variables differ slightly: MongoDB exposes MONGO_URL (drivers) and DATABASE_URL (Prisma), MariaDB MYSQL_URL, and Redis and Valkey REDIS_URL.
Persistence and backups
Each database template stores data on a volume, so a redeploy keeps it. The Tracklayer templates also run a daily backup job that writes to a Railway Bucket: the pgvector template keeps 14 days and the backup runs at 03:15 UTC. The point-in-time recovery template archives WAL segments instead and rebuilds the database as of a time you choose in a separate restore service. Test a restore before you rely on any backup.
Cost
Railway bills usage. The template notes give estimates, not measurements: the pgvector Postgres at about $1.50 a month idle and $16 typical, Redis at $2.50 idle and $10.50 typical, MariaDB at $2.70 idle and $16 typical. Memory, volume size, bucket storage and egress drive the bill. Most of the idle cost of the Redis template is RedisInsight, which you can remove. Keycloak’s figure is not stated in its notes, so none is given here.
Limitations and licences
- MongoDB runs as one replica-set member, so there is no failover.
- Redis and Valkey run a single primary. Keycloak runs one replica with local caches.
- Keycloak password reset and email verification need outbound SMTP, which Railway allows on the Pro plan.
- MongoDB Community Server is SSPL-1.0. Redis 8 is RSALv2, SSPLv1 or AGPLv3 at your choice, and RedisInsight is SSPLv1. Valkey is BSD-3-Clause. Keycloak is Apache-2.0.
- These are community templates, not affiliated with the upstream projects or Railway, and this is not legal advice.
Other options
Browse every database template in the ranking of Postgres templates on Railway, or read about Tracklayer and the other guides.
FAQ
Do I need a cache and an auth server as well as a database?
Not at the start. A database is the only required piece for most apps. Add Redis or Valkey when you need caching, queues or fast counters, and Keycloak when you need single sign-on, SAML or your own identity provider rather than a login library inside the app.
Should my database have a public URL?
Only if something outside Railway needs it, such as a desktop client or a frontend host that connects directly. The templates keep a TCP proxy on for compatibility with Railway's own database templates; you can remove it under Settings, Networking for a private-only database. Public Redis, Valkey and MongoDB proxy traffic is not encrypted and is billed as egress.
What do these backend templates cost on Railway?
Railway bills usage: memory, CPU, volumes, bucket storage and egress. The template notes estimate about $1.50 a month idle and $16 typical for the pgvector Postgres, $2.50 idle and $10.50 typical for Redis, and $2.70 idle and $16 typical for MariaDB. These are estimates, not measurements.
Are MongoDB and Redis free to use in a commercial app?
MongoDB Community Server uses the Server Side Public License v1 and Redis 8 is offered under RSALv2, SSPLv1 or AGPLv3 at your choice. Using either as your own app's database is common, but offering them as a service to third parties has conditions. Valkey is BSD-3-Clause. This is not legal advice; check the terms for your case.