
Deploy Dub: Self-Hosted Link Management
Self-host Dub link management, analytics, and QR codes
Just deployed
MySQL
Just deployed
/var/lib/mysql
PlanetScale Proxy
Just deployed
Deploy and Host Dub: Self-Hosted Link Management on Railway
Dub is an open-source link management and attribution platform for creating branded short links, managing custom domains, generating QR codes, tracking clicks and conversions, and running partner programs.
This community template adapts Dub for Railway by deploying the application with Railway MySQL and a PlanetScale-compatible HTTP proxy. The database services, internal networking, application domain, and core secrets are wired automatically.
Community-maintained template. Not affiliated with or endorsed by Dub. Dub is licensed under AGPL-3.0.
What This Template Deploys
The template creates three Railway services:
- Dub — the Next.js web application and link redirect service
- MySQL — the primary database for users, projects, links, and metadata
- PlanetScale Proxy — a compatibility layer that allows Dub’s PlanetScale serverless driver to communicate with Railway MySQL
The template also configures:
- Private database connectivity
- Build-time and runtime database URLs
- The Railway-generated application domain
- NextAuth, encryption, and cron secrets
- Database schema synchronization during deployment
This removes the need to provision a separate PlanetScale database or manually connect Dub’s two database access methods.
What You Can Use Dub For
- Create short links using your own branded domains
- Organize and manage campaign links
- Generate QR codes for links and campaigns
- Track clicks, referrers, devices, and conversions
- Attribute signups, leads, and purchases to individual links
- Build affiliate and partner programs with Dub Partners
- Provide link management tools inside another application using Dub’s APIs
Additional Services Required
The Railway infrastructure is deployed automatically, but a working Dub installation still requires credentials for several external services.
Upstash
Dub uses:
- Upstash Redis for caching link metadata and serving redirects
- QStash for queues and background jobs
Add the Redis REST URL and token, together with the QStash token and signing keys, to the Dub service variables.
Tinybird
Dub uses Tinybird to store and query click-event analytics.
Create a Tinybird workspace, add its API URL and admin token, and deploy the Tinybird datasources included in the repository.
Click analytics will not work until these datasources have been deployed.
Object Storage
Dub stores project logos, user avatars, and custom social-card images in S3-compatible object storage.
Supported options include:
- Cloudflare R2
- Amazon S3
- A separately deployed MinIO service
Configure the storage endpoint, access credentials, public and private bucket names, and public asset URL.
Authentication
Configure at least one login method:
- GitHub OAuth
- Google OAuth
- Resend for email magic links
OAuth is generally the simplest option because it does not require an email delivery service.
For GitHub OAuth, use the following callback format:
https://your-domain.example/api/auth/callback/github
Getting Started
- Click Deploy and allow the Dub, MySQL, and PlanetScale Proxy services to build.
- Open the generated Railway domain so you know the final hostname.
- Create an OAuth application using that hostname for the callback URL.
- Configure Upstash Redis and QStash.
- Configure Tinybird and deploy Dub’s analytics datasources.
- Configure Cloudflare R2, Amazon S3, or MinIO.
- Add the required credentials to the Dub service variables.
- Redeploy the Dub service.
- Open the Railway domain and sign in.
To use your own application domain, add it to the Dub service and update NEXT_PUBLIC_APP_DOMAIN to the new hostname.
Your branded short-link domains can then be added and managed from inside Dub.
Important Deployment Notes
- This is a Railway-ready fork of Dub rather than an automatically updated deployment of the latest upstream release. Review the repository before upgrading.
- Tinybird datasources must be deployed separately before analytics becomes available.
- The current fork documents compatibility differences between Tinybird Classic and newer Forward workspaces. Check the repository notes when creating your workspace.
- Country and city analytics provided through Vercel-specific geolocation helpers may not be populated on Railway. Clicks and other available metadata are still recorded.
- Dub’s scheduled API jobs are not created automatically. Add Railway Cron services for any scheduled jobs you need and authenticate them using
CRON_SECRET. - Stripe billing and Upstash Vector integrations are optional and require additional credentials only when those features are enabled.
- Because Dub uses the AGPL-3.0 license, modified versions made available over a network may require users to be given access to the corresponding source code.
Why Deploy Dub on Railway?
The official Dub architecture normally combines several infrastructure providers. This template moves the main application and relational database into one Railway project while retaining the external services Dub uses for caching, queues, analytics, and file storage.
Railway provides:
- A persistent managed MySQL database
- Private networking between application services
- Generated and referenced environment variables
- Centralized logs and deployment history
- Custom domains and automatic TLS
- Straightforward scaling for the Dub web service
The result is a practical starting point for running your own branded link-management and attribution platform without manually adapting Dub’s database architecture to Railway.
Template Content
QSTASH_TOKEN
STORAGE_BASE_URL
public bucket URL, e.g. https://pub-xxxx.r2.dev
STORAGE_ENDPOINT
e.g. https://.r2.cloudflarestorage.com
TINYBIRD_API_KEY
Object storage: Cloudflare R2 or AWS S3 (or a MinIO service on Railway)
STORAGE_ACCESS_KEY_ID
STORAGE_PUBLIC_BUCKET
STORAGE_PRIVATE_BUCKET
Login: configure at least one method. OAuth needs no email service.
UPSTASH_REDIS_REST_URL
QSTASH_NEXT_SIGNING_KEY
Tinybird: tinybird.co -> workspace -> Tokens (admin token)
UPSTASH_REDIS_REST_TOKEN
Upstash QStash: console.upstash.com -> QStash (QSTASH_URL default above)
STORAGE_SECRET_ACCESS_KEY
QSTASH_CURRENT_SIGNING_KEY
MySQL
mysql:9.4PlanetScale Proxy
acewebs/dub-railway