service-types

Detailed explanation of each service type available on Render.

Render Service Types

Detailed explanation of each service type available on Render. Choose the right service type based on your application's needs.

Web Services (type: web)

Purpose

Web services are HTTP servers that handle incoming requests from the internet. They're publicly accessible via HTTPS URLs.

Use Cases

Key Characteristics

Required Configuration

type: web
name: my-api
runtime: node
buildCommand: npm ci
startCommand: npm start

Best Practices

  1. Bind to environment PORT:
const PORT = process.env.PORT || 3000;
app.listen(PORT, '0.0.0.0');
  1. Add health check endpoint:
app.get('/health', (req, res) => {
  res.status(200).json({ status: 'ok' });
});
  1. Use appropriate timeouts: Web requests should complete within 30 seconds
  1. Implement graceful shutdown: Handle SIGTERM signals properly

Worker Services (type: worker)

Purpose

Worker services run background tasks without handling HTTP requests. They're not publicly accessible.

Use Cases

Key Characteristics

Required Configuration

type: worker
name: queue-processor
runtime: python
buildCommand: pip install -r requirements.txt
startCommand: celery -A tasks worker --loglevel=info

Best Practices

  1. Connect to message queue:
import redis
r = redis.from_url(os.environ['REDIS_URL'])
  1. Implement retry logic: Handle failures gracefully
  1. Monitor queue depth: Track pending jobs
  1. Log processing status: Make debugging easier
  1. Graceful shutdown: Finish current jobs before exiting

Common Patterns

Node.js with BullMQ:

type: worker
name: job-processor
runtime: node
buildCommand: npm ci
startCommand: node worker.js
envVars:
  - key: REDIS_URL
    fromDatabase:
      name: redis
      property: connectionString

Python with Celery:

type: worker
name: celery-worker
runtime: python
buildCommand: pip install -r requirements.txt
startCommand: celery -A app.celery worker
envVars:
  - key: REDIS_URL
    fromDatabase:
      name: redis
      property: connectionString

Cron Jobs (type: cron)

Purpose

Cron jobs run scheduled tasks on a repeating schedule. They execute, complete, and shut down.

Use Cases

Key Characteristics

Required Configuration

type: cron
name: daily-backup
runtime: node
schedule: "0 2 * * *"  # Daily at 2 AM UTC
buildCommand: npm ci
startCommand: node scripts/backup.js

Schedule Format

Standard cron syntax: minute hour day month weekday

Common schedules:

| Schedule | Description | |----------|-------------| | /5 | Every 5 minutes | | 0 | Every hour | | 0 0 | Daily at midnight UTC | | 0 9 1-5 | Weekdays at 9 AM UTC | | 0 0 1 | First day of each month | | 0 9 1 | Every Monday at 9 AM UTC |

Best Practices

  1. Handle failures gracefully: Jobs should be idempotent
  1. Log completion status: Track success/failure
  1. Set appropriate timeouts: Match expected job duration
  1. Use UTC times: All schedules are UTC-based
  1. Test thoroughly: Test with different data scenarios

Example Use Cases

Daily Database Backup:

type: cron
name: db-backup
runtime: python
schedule: "0 1 * * *"  # 1 AM UTC daily
buildCommand: pip install -r requirements.txt
startCommand: python scripts/backup.py
envVars:
  - key: DATABASE_URL
    fromDatabase:
      name: postgres
      property: connectionString
  - key: S3_BUCKET
    value: my-backups

Hourly Cache Refresh:

type: cron
name: cache-refresh
runtime: node
schedule: "0 * * * *"  # Top of every hour
buildCommand: npm ci
startCommand: node scripts/refresh-cache.js

Static Sites (type: web + runtime: static)

Purpose

Serve static HTML, CSS, and JavaScript files via CDN. No backend runtime.

Use Cases

Key Characteristics

Required Configuration

type: web
name: frontend
runtime: static
buildCommand: npm ci && npm run build
staticPublishPath: ./dist  # or ./build, ./out, ./public

Routing for SPAs

Single Page Applications need rewrite rules to handle client-side routing:

type: web
name: react-app
runtime: static
buildCommand: npm ci && npm run build
staticPublishPath: ./build
routes:
  - type: rewrite
    source: /*
    destination: /index.html

Custom Headers

Add cache control and security headers:

type: web
name: static-site
runtime: static
buildCommand: npm ci && npm run build
staticPublishPath: ./dist
headers:
  # Cache static assets
  - path: /static/*
    name: Cache-Control
    value: public, max-age=31536000, immutable

  # Security headers
  - path: /*
    name: X-Frame-Options
    value: DENY
  - path: /*
    name: X-Content-Type-Options
    value: nosniff

Build Filters

For monorepos, only build when frontend files change:

type: web
name: frontend
runtime: static
buildCommand: npm ci && npm run build
staticPublishPath: ./dist
buildFilter:
  paths:
    - frontend/**
  ignoredPaths:
    - frontend/**/*.test.js
    - frontend/README.md

Best Practices

  1. Optimize build output: Minify, compress, tree-shake
  1. Use proper cache headers: Long cache for hashed assets
  1. Add security headers: Protect against common attacks
  1. Configure SPA routing: Add rewrite rules for client routing
  1. Handle 404s: Create custom 404.html page

Private Services (type: pserv)

Purpose

Internal services accessible only within your Render account. Not exposed to the internet.

Use Cases

Key Characteristics

Required Configuration

type: pserv
name: internal-api
runtime: node
buildCommand: npm ci
startCommand: npm start

Accessing Private Services

From other services in the same account:

// Use .render-internal.com domain
const API_URL = 'http://internal-api.render-internal.com:10000';

Or use service references:

services:
  - type: web
    name: frontend
    runtime: node
    envVars:
      - key: INTERNAL_API_URL
        fromService:
          name: internal-api
          type: pserv
          property: hostport

Best Practices

  1. Use internal DNS: Always use .render-internal.com domains
  1. No authentication needed: Already isolated to account
  1. Fast communication: Low latency between services
  1. Simplify architecture: No need for external load balancers

Comparison Table

| Feature | Web | Worker | Cron | Static | Private | |---------|-----|--------|------|--------|---------| | Public URL | ✅ Yes | ❌ No | ❌ No | ✅ Yes | ❌ No | | Port Binding | ✅ Required | ❌ Not needed | ❌ Not needed | ❌ N/A | ✅ Required | | Health Checks | ✅ Yes | ❌ No | ❌ No | ❌ N/A | ✅ Yes | | Runtime | ✅ Yes | ✅ Yes | ✅ Yes | ❌ No | ✅ Yes | | Persistent | ✅ Yes | ✅ Yes | ❌ No | ✅ Yes | ✅ Yes | | Scaling | ✅ Yes | ✅ Yes | ❌ No | ✅ Yes | ✅ Yes | | Use Case | HTTP servers | Background jobs | Scheduled tasks | Static files | Internal services |

Choosing the Right Service Type

Use Web Service when:

Use Worker Service when:

Use Cron Job when:

Use Static Site when:

Use Private Service when: