Deployment Guide - Archety Backend¶
Complete guide for deploying the Archety backend to dev and production environments.
Table of Contents¶
- Overview
- Prerequisites
- Environment Setup
- Deployment Workflows
- Rollback Procedures
- Monitoring & Debugging
- Common Issues
- Emergency Procedures
Overview¶
Architecture¶
graph LR
GitHub[GitHub Repository] --> Actions[GitHub Actions]
Actions --> RailwayDev[Railway Dev]
Actions --> RailwayProd[Railway Prod]
subgraph "Environments"
RailwayDev
RailwayProd
end
Environments¶
-
:material-dev-to-app:{ .lg .middle } Development
Auto-deploys from
devbranch. -
Production
Manual deploy from
master(canonical domain is typicallyhttps://api.ikiro.ai).
Prerequisites¶
Required Access¶
-
GitHub Access
Write permissions required for the repository.
-
Railway Account
Project access and CLI installed (
npm install -g @railway/cli). -
Secrets Configured
See Railway Setup Guide.
Required Secrets¶
Configure in GitHub Settings
Go to Settings β Secrets and variables β Actions to configure these.
| Secret Name | Description | Source |
|---|---|---|
RAILWAY_TOKEN |
Railway API token | railway token |
RAILWAY_DEV_SERVICE_ID |
Dev service ID | railway service (select dev) |
RAILWAY_PROD_SERVICE_ID |
Prod service ID | railway service (select prod) |
OPENAI_API_KEY_DEV |
Dev OpenAI key (tests) | OpenAI Platform |
OPENAI_API_KEY_PROD |
Prod OpenAI key (tests) | OpenAI Platform |
MEM0_API_KEY_DEV |
Dev mem0 key (tests; legacy memory) | mem0 dashboard |
MEM0_API_KEY_PROD |
Prod mem0 key (tests; legacy memory) | mem0 dashboard |
PERPLEXITY_API_KEY_DEV |
Dev Perplexity key (optional tests) | Perplexity dashboard |
Environment Setup¶
Initial Setup¶
If you haven't set up Railway environments yet, follow the Railway Setup Guide first.
Quick Verification¶
# Verify Railway CLI is installed
railway --version
# Verify you're logged in
railway whoami
# Check current service
railway status
Deployment Workflows¶
1. Deploy to Development (Automatic)¶
Trigger: Push to dev branch
Steps:
# Create or checkout dev branch
git checkout dev
# Make your changes
git add .
git commit -m "feat: add new feature"
# Push to dev branch
git push origin dev
What Happens:
- β GitHub Actions runs tests
- β If tests pass, auto-deploys to Railway dev service
- β Health check verifies deployment
- β You get notified via GitHub Actions
Check Deployment:
# View GitHub Actions run
# Go to: https://github.com/YOUR_REPO/actions
# Check Railway logs
railway service # Select dev
railway logs
2. Deploy to Production (Manual)¶
Method A: Manual Workflow Dispatch
- Go to GitHub β Actions β "Deploy to Production"
- Click "Run workflow"
- Type
DEPLOY TO PRODUCTION(exactly) in the confirmation field - Click "Run workflow"
Method B: Version Tag
# Make sure master is up to date
git checkout master
git merge dev
git push origin master
# Create a version tag
git tag v1.0.0
git push origin v1.0.0
What Happens:
- β GitHub Actions validates request
- β Runs full test suite
- β Checks for exposed secrets
- βΈοΈ Manual approval required (GitHub environment protection)
- β Deploys to Railway prod service
- β Health check verifies deployment
- β Creates deployment record on GitHub
Check Deployment:
# View GitHub Actions run
# Go to: https://github.com/YOUR_REPO/actions
# Check Railway logs
railway service # Select prod
railway logs
# Run smoke tests
ENVIRONMENT_URL=https://archety-backend-prod.up.railway.app python tests/smoke/smoke_tests.py
3. Hotfix to Production (Emergency)¶
When: Critical bug in production that needs immediate fix
Steps:
# Create hotfix branch from master
git checkout master
git pull origin master
git checkout -b hotfix/critical-bug-fix
# Make the fix
git add .
git commit -m "hotfix: fix critical bug"
# Push and create PR
git push origin hotfix/critical-bug-fix
# Create PR targeting master
# After review and tests pass, merge PR
# Deploy immediately
git checkout master
git pull origin master
git tag v1.0.1-hotfix
git push origin v1.0.1-hotfix
Rollback Procedures¶
Rollback via Railway Dashboard¶
Fastest method for production issues:
- Go to Railway dashboard
- Select production service
- Click on "Deployments" tab
- Find the last known good deployment
- Click "Redeploy"
Time: ~2-3 minutes
Rollback via CLI¶
# Switch to production service
railway service # Select prod
# View recent deployments
railway logs
# Redeploy previous version
railway redeploy <DEPLOYMENT_ID>
Rollback via Git¶
# Revert the problematic commit
git revert <BAD_COMMIT_SHA>
# Push to master
git push origin master
# Deploy (manual trigger or tag)
git tag v1.0.2-revert
git push origin v1.0.2-revert
Monitoring & Debugging¶
Health Checks¶
Dev:
Prod:
Expected response:
View Logs¶
Railway Dashboard: 1. Go to Railway project 2. Select service (dev or prod) 3. Click "Logs" tab 4. Filter by level, time, etc.
Railway CLI:
# Dev logs
railway service # Select dev
railway logs --follow
# Prod logs
railway service # Select prod
railway logs --tail 100
Run Smoke Tests¶
# Test dev
ENVIRONMENT_URL=https://archety-backend-dev.up.railway.app \
python tests/smoke/smoke_tests.py
# Test prod
ENVIRONMENT_URL=https://archety-backend-prod.up.railway.app \
python tests/smoke/smoke_tests.py
Check Sentry for Errors¶
- Go to Sentry Dashboard
- Filter by environment (dev or production)
- Review recent errors
- Check error trends
Database Health¶
# Connect to dev database
railway service # Select dev
railway connect postgres
# Connect to prod database
railway service # Select prod
railway connect postgres
# Check connections
SELECT count(*) FROM pg_stat_activity;
# Check table sizes
SELECT schemaname, tablename, pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) AS size
FROM pg_tables
ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;
Common Issues¶
Issue: Deployment Failed - Tests Not Passing¶
Symptoms: - GitHub Actions shows red X - Tests fail in CI
Solution:
# Run tests locally first
python -m pytest tests/ -v
# Fix any failing tests
git add .
git commit -m "fix: resolve test failures"
git push origin dev
Issue: Health Check Failing After Deployment¶
Symptoms: - Deployment succeeds but health check returns 500 - Application crashes on startup
Check:
# View logs immediately
railway logs --tail 100
# Common causes:
# 1. Missing environment variables
railway variables
# 2. Database migration failed
railway run alembic upgrade head
# 3. Database connection issues
railway connect postgres # Check if database is accessible
Solution:
Issue: Database Migration Failed¶
Symptoms: - Logs show "migration failed" - Database schema out of sync
Solution:
# Check current migration version
railway run alembic current
# Check migration history
railway run alembic history
# Try manual migration
railway run alembic upgrade head
# If stuck, downgrade and retry
railway run alembic downgrade -1
railway run alembic upgrade head
Issue: Environment Variables Not Updating¶
Symptoms: - Changed variables in Railway UI - Application still using old values
Solution:
# Redeploy service (triggers reload of env vars)
railway redeploy
# Or, restart service
railway run -- /bin/sh -c "kill 1"
Issue: CORS Errors in Frontend¶
Symptoms: - Frontend gets CORS errors - Browser console shows origin not allowed
Solution:
# Check BASE_URL is set correctly
railway variables | grep BASE_URL
# Update BASE_URL for environment
railway variables set BASE_URL=https://archety-backend-prod.up.railway.app
# Redeploy
railway redeploy
Issue: Out of Memory (OOM)¶
Symptoms: - Service crashes randomly - Logs show "Killed" or OOM errors
Solution:
- Upgrade Railway plan (if on free tier)
- Optimize memory usage:
Emergency Procedures¶
π¨ Service is Down¶
Priority: CRITICAL
Steps:
-
Check health endpoint:
-
Check Railway status:
- Go to Railway dashboard
-
Check if service is running
-
Check logs for crashes:
-
Rollback immediately:
-
Notify team:
- Post in team chat
- Update status page (if applicable)
π¨ Database Connection Lost¶
Priority: HIGH
Steps:
-
Check database status:
-
Check database logs:
- Go to Railway dashboard
- Select PostgreSQL service
-
View logs
-
Restart database if needed:
-
Railway dashboard β PostgreSQL β Settings β Restart
-
Restart web service:
π¨ Exposed Secrets in Code¶
Priority: CRITICAL
Steps:
-
Immediately rotate all exposed secrets:
-
Update Railway environment variables:
-
Rotate external API keys:
- Supermemory: Generate new key at supermemory.ai dashboard
- mem0 (if using legacy fallback): Generate new key in dashboard
- OpenAI: Rotate key in platform
-
OAuth: Update Google Console credentials
-
Remove secrets from git history:
-
Audit access logs for potential unauthorized usage
Deployment Checklist¶
Pre-Deployment¶
- All tests passing locally
- Code reviewed and approved
- Environment variables verified
- Database migrations tested
- Changelog updated
During Deployment¶
- Monitor GitHub Actions
- Watch Railway logs during deployment
- Health check passes
- Smoke tests pass
Post-Deployment¶
- Verify key user flows work
- Check Sentry for new errors
- Monitor performance metrics
- Update team on deployment status
- Tag release in GitHub (if production)
Additional Resources¶
Last Updated: 2025-01-11 Maintained by: Engineering Team