Database, cache and auth for a vibe-coded app on Railway

By Tracklayer · Updated 2026-11-20

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 Railway

What 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

TemplateCreatorDeploymentsServices
PostgreSQLRailway Templates394,2571
n8nThalles Passos's Projects5,8502
Langflow–2,8522
pgvectorBrody's Projects2,0771
PostGISRailway Templates1,5051
n8nBruno's Team1,2932
ExpressJS PostgreSQLopqr's Projects1,1012
medusajs ecommerce Nextjs, Postgres, RedisRasmus Puls's Projects1,0364

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).

  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.
  2. Check that it works. Copy DATABASE_PUBLIC_URL, add ?sslmode=require (the certificate is self-signed) and connect with psql. SELECT extversion FROM pg_extension WHERE extname = 'vector'; confirms pgvector.
  3. Create a role for your app. The template’s own advice is to use a dedicated role instead of the postgres superuser.
  4. Point your app at it. In the app service, reference DATABASE_POOL_URL for normal queries. It goes through PgBouncer on the private network. Use DATABASE_URL, the direct private connection, for migrations, index builds and LISTEN/NOTIFY. Prisma needs ?pgbouncer=true on the pooled URL.
  5. 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

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.