Deploy to Production
Get your DeltaBase application live
This guide walks you through deploying your DeltaBase application to production.
Prerequisites
Section titled “Prerequisites”- A DeltaBase account (sign up)
- Your application code ready to deploy
- Node.js 18+ installed
Step 1: Get Your API Key
Section titled “Step 1: Get Your API Key”- Sign in to the DeltaBase Panel
- Select or create your organization
- Go to API Keys in the sidebar
- Click Create API Key
- Give it a name (e.g., “Production Deployment”)
- Copy the key - you won’t see it again!
Important: Store your API key securely. Never commit it to version control.
Step 2: Create Your Infrastructure Config
Section titled “Step 2: Create Your Infrastructure Config”Create a deltabase.config.ts file in your project:
import type { InfrastructureConfig as DeltaBaseConfig } from '@delta-base/server';
const config: DeltaBaseConfig = { eventStores: [ { name: process.env.DELTABASE_EVENT_STORE_NAME || 'my-app-production', description: 'Production event store', subscriptions: [ // Add your projections here { id: 'my-projection', eventFilter: ['user.*', 'order.*'], subscriberType: 'webhook', webhook: { url: `${process.env.SERVICE_URL}/api/projections/events`, headers: { Authorization: `Bearer ${process.env.PROJECTION_AUTH_TOKEN}`, }, retryPolicy: { maxAttempts: 5, backoffMinutes: 2, }, }, }, ], }, ],};
export default config;Step 3: Set Up Environment Variables
Section titled “Step 3: Set Up Environment Variables”For Your Application
Section titled “For Your Application”Create environment variables for your production environment:
# DeltaBase connectionDELTABASE_API_KEY=db:prod:org-xxx:your-api-keyDELTABASE_BASE_URL=https://api.delta-base.comDELTABASE_EVENT_STORE_NAME=my-app-production
# Your service URL (for webhooks)SERVICE_URL=https://my-app.example.com
# Projection authenticationPROJECTION_AUTH_TOKEN=your-secret-projection-tokenFor Deployment
Section titled “For Deployment”Set the API key for infrastructure deployment:
export DELTABASE_API_KEY=db:prod:org-xxx:your-api-keyStep 4: Deploy Infrastructure
Section titled “Step 4: Deploy Infrastructure”Deploy your event stores and subscriptions:
# Preview changes firstpnpx @delta-base/cli deploy --dry-run
# Deploy for realpnpx @delta-base/cli deployYou should see output like:
Deploying DeltaBase infrastructure...
Event Stores: ✓ my-app-production (created)
Subscriptions: ✓ my-projection (created)
Deployment complete!Step 5: Update Your Application Code
Section titled “Step 5: Update Your Application Code”Update your DeltaBase client to use production settings:
import { DeltaBase } from '@delta-base/server';
// Production configurationconst deltabase = new DeltaBase({ apiKey: process.env.DELTABASE_API_KEY, baseUrl: process.env.DELTABASE_BASE_URL || 'https://api.delta-base.com',});
const eventStore = deltabase.getEventStore( process.env.DELTABASE_EVENT_STORE_NAME);
// Now use eventStore as normalawait eventStore.appendToStream('user-123', [{ type: 'user.created', data: { name: 'Alice', email: 'alice@example.com' },}]);Local vs Production Configuration
Section titled “Local vs Production Configuration”A common pattern is to switch based on environment:
import { DeltaBase } from '@delta-base/server';
const isProduction = process.env.NODE_ENV === 'production';
const deltabase = new DeltaBase({ apiKey: isProduction ? process.env.DELTABASE_API_KEY : undefined, baseUrl: isProduction ? 'https://api.delta-base.com' : 'http://localhost:8787',});Step 6: Deploy Your Application
Section titled “Step 6: Deploy Your Application”Deploy your application to your hosting provider. Here are examples for common platforms:
Cloudflare Workers
Section titled “Cloudflare Workers”# Set secretswrangler secret put DELTABASE_API_KEYwrangler secret put PROJECTION_AUTH_TOKEN
# Deploywrangler deployYour wrangler.jsonc:
{ "name": "my-app", "main": "src/index.ts", "compatibility_date": "2024-01-01", "vars": { "DELTABASE_BASE_URL": "https://api.delta-base.com", "DELTABASE_EVENT_STORE_NAME": "my-app-production" }}Vercel
Section titled “Vercel”# Set environment variablesvercel env add DELTABASE_API_KEY productionvercel env add DELTABASE_BASE_URL productionvercel env add DELTABASE_EVENT_STORE_NAME productionvercel env add PROJECTION_AUTH_TOKEN production
# Deployvercel --prodDocker / Self-Hosted
Section titled “Docker / Self-Hosted”FROM node:20-alpine
WORKDIR /appCOPY . .RUN npm install
ENV DELTABASE_BASE_URL=https://api.delta-base.com
CMD ["npm", "start"]Run with:
docker run -e DELTABASE_API_KEY=your-key \ -e DELTABASE_EVENT_STORE_NAME=my-app-production \ -e PROJECTION_AUTH_TOKEN=your-token \ my-appStep 7: Verify Deployment
Section titled “Step 7: Verify Deployment”Check Event Store
Section titled “Check Event Store”Use the DeltaBase Panel to verify your event store is working:
- Go to app.delta-base.com
- Select your organization
- Find your event store in the list
- Check the event count and status
Test Event Appending
Section titled “Test Event Appending”Send a test event from your deployed application:
const result = await eventStore.appendToStream('test-stream', [{ type: 'test.event', data: { message: 'Production deployment successful!' },}]);
console.log('Event appended, global position:', result.globalPosition);Check Webhooks
Section titled “Check Webhooks”If you have projections:
- Append an event that matches your subscription filter
- Check your webhook endpoint logs
- Verify the event was received and processed
Deployment Checklist
Section titled “Deployment Checklist”Before going live, verify:
- API key is set and working
- Event store is created (
pnpx @delta-base/cli deploy) - Application can append events
- Webhook URLs are publicly accessible
- Projection authentication is configured
- Error handling is in place
- Monitoring/logging is set up
Monitoring & Observability
Section titled “Monitoring & Observability”DeltaBase Panel
Section titled “DeltaBase Panel”The Panel provides built-in monitoring:
- Event counts and throughput
- Subscription health and delivery status
- Stream statistics
- Error logs
Application Logging
Section titled “Application Logging”Log important operations:
try { const result = await eventStore.appendToStream(streamId, events); console.log(`Appended ${events.length} events to ${streamId}`, { globalPosition: result.globalPosition, version: result.nextExpectedStreamVersion, });} catch (error) { console.error('Failed to append events', { streamId, error: error.message, }); throw error;}Health Checks
Section titled “Health Checks”Add a health check endpoint:
app.get('/health', async (c) => { try { // Test DeltaBase connection await eventStore.readStream('health-check', { limit: 1 }); return c.json({ status: 'healthy', deltabase: 'connected' }); } catch (error) { return c.json({ status: 'unhealthy', error: error.message }, 500); }});Troubleshooting
Section titled “Troubleshooting””Invalid API key”
Section titled “”Invalid API key””- Verify the API key is correct
- Check it hasn’t been revoked
- Ensure you’re using the production key (not a development key)
“Event store not found”
Section titled ““Event store not found””- Run
pnpx @delta-base/cli deployto create the event store - Verify
DELTABASE_EVENT_STORE_NAMEmatches your config
”Webhook delivery failed”
Section titled “”Webhook delivery failed””- Verify your webhook URL is publicly accessible
- Check your server is running and healthy
- Verify
PROJECTION_AUTH_TOKENis set correctly on both sides - Check server logs for errors
”Rate limited”
Section titled “”Rate limited””- DeltaBase has rate limits to protect the service
- Implement exponential backoff in your application
- Contact support if you need higher limits
What’s Next?
Section titled “What’s Next?”- Infrastructure as Code - Advanced deployment configurations
- Real-Time Events - Add WebSocket connections
- CQRS Implementation - Build a complete CQRS architecture