4 months ago
My project has several services that it deploys. I want to specify order of deployment for all the services. How can I do it?
1 Replies
4 months ago
You can't specify a strict deployment order for services in a Railway project. By design, Railway deploys all services in parallel to make the process as fast as possible.
The recommended approach is to make each service resilient enough to wait for its dependencies to be ready. Instead of controlling the deployment order, you build retry logic into your applications' startup process.
## How to Make Your Services Wait for a Database
The most common reason for wanting an ordered deployment is to ensure a database is running before a backend application tries to connect to it. You can solve this by using a simple startup script.
This script will act as a wrapper. It will try to connect to your database in a loop, and only when the connection is successful will it start your main application.
Create a
startup.shfile in your service's root directory:Bash
#!/bin/sh # This script waits for the database to be ready before starting the app. # Replace DB_HOST and DB_PORT with your actual database env variables. echo "Waiting for database..." # We use netcat (nc) to check if the port is open. # The '-z' flag makes nc scan for listening daemons without sending data. while ! nc -z $DB_HOST $DB_PORT; do sleep 1 # wait for 1 second before trying again done echo "Database started!" # Run the main command to start your application # (e.g., the command from your original Procfile or Dockerfile CMD) exec "$@"Note: If your base image doesn't have
netcat, you may need to install it. For Postgres, you can usepg_isreadyfor a more robust check.Make the script executable:
chmod +x startup.shUpdate your start command to use this script. For example, if you're using a
Procfile:Before:
web: npm startAfter:
web: ./startup.sh npm start
Now, when your service deploys, it will pause and wait for the database service to become available before starting the main Node.js process, effectively solving the dependency issue without needing a strict deployment order.
4 months ago
As far as I know, the only way you can do that is if a service depends on other services through referenced env vars.
4 months ago
For example: you deploy service X and service Y, service X has a referenced var that belongs to service Y so service X will wait for the service Y to deploy first
4 months ago

4 months ago
langfuse-web is queued because it depends on clickhouse (through referenced env vars)
oh cool, @Medim can you share some documentation on how to reference env vars from one service to another service?
4 months ago
!s
Status changed to Solved medim • 4 months ago