Job System Overview
Background jobs handle:- Sending signing invitation emails
- Document completion notifications
- Webhook delivery
- Recipient expiration checks
- Document cleanup
- Email verification
- Password reset emails
Job Providers
Documenso supports two background job providers:Local Provider
Built-in job system using PostgreSQL. Recommended for most deployments.
Inngest
Cloud-based job orchestration for enterprise deployments.
Local Provider (Default)
The local provider uses PostgreSQL to store and process jobs. It’s simple, reliable, and requires no external services.Configuration
Set to
"local" to use the built-in job system.How It Works
- Job Creation: When a job is triggered (e.g., sending an email), a record is created in the
BackgroundJobtable - Job Dispatch: The job is immediately dispatched to an HTTP endpoint on the same server
- Job Execution: The endpoint processes the job and updates the database
- Retry Logic: Failed jobs are automatically retried with exponential backoff
- Cron Jobs: A polling mechanism checks for scheduled jobs every 30 seconds
Architecture
Job Lifecycle
- PENDING: Job created, waiting for execution
- PROCESSING: Job is currently being executed
- COMPLETED: Job finished successfully
- FAILED: Job failed after maximum retries
Retry Behavior
- Maximum Retries: 3 attempts per job
- Retry Strategy: Exponential backoff
- Failed Jobs: Marked as FAILED after max retries
- Task-Level Retries: Individual tasks within a job have their own retry logic
Cron Jobs
The local provider includes a cron poller that runs every 30 seconds to check for scheduled jobs:- Deterministic job IDs prevent duplicate execution across multiple instances
- Random jitter (0-5 seconds) prevents thundering herd
- Only the latest cron slot is executed (no backfill after downtime)
Scaling Considerations
Single Instance:- Works perfectly out of the box
- All jobs processed on the same server
- Job execution is distributed across instances
- Cron jobs use deterministic IDs to prevent duplicates
- If a job fails on one instance, another can pick it up on retry
Database Impact
The local provider creates two tables:BackgroundJob: Stores job metadata and statusBackgroundJobTask: Stores individual task results (for idempotent retry)
Configuration Example
.env
Monitoring
Query job status:Inngest Provider (Enterprise)
Inngest is a cloud-based job orchestration platform with advanced features for enterprise deployments.When to Use Inngest
- High-volume deployments (100,000+ documents/month)
- Need for advanced observability and debugging
- Complex workflow orchestration
- Distributed teams requiring shared job visibility
- Compliance requirements for job execution audit trails
Configuration
Set to
"inngest" to use Inngest.Inngest event key for authentication.
Alternative environment variable name for Inngest event key.
Inngest application ID.
Setup Steps
- Create Inngest Account Sign up at inngest.com
- Get Event Key Copy your event key from the Inngest dashboard
-
Configure Documenso
.env
- Deploy and Register Functions When you deploy Documenso, it will automatically register job functions with Inngest
Features
- Web Dashboard: Visual job monitoring and debugging
- Replay Failed Jobs: Retry failed jobs from the dashboard
- Function Versioning: Deploy new job logic without downtime
- Parallel Execution: Optimize parallelism automatically
- Event Replay: Replay historical events
- Advanced Scheduling: Complex cron expressions and delays
Cost
Inngest pricing (as of 2024):- Free Tier: 50,000 function runs/month
- Paid Plans: Starting at $20/month
Job Types in Documenso
Document Workflow Jobs
send-signing-email- Triggered when a document is sent for signing
- Sends invitation emails to recipients
- Retries on failure
- Triggered when all recipients sign
- Sends completion notifications
- Triggers webhooks
- Triggered when a recipient rejects
- Notifies document owner
- Triggers webhooks
Scheduled Jobs (Cron)
expire-recipients-sweep- Runs: Every hour (
0 * * * *) - Checks for expired recipient invitations
- Processes up to 1,000 recipients per run
- Sends expiration notifications
Webhook Jobs
trigger-webhook- Delivers webhook payloads to configured endpoints
- Retries with exponential backoff
- Logs delivery attempts
Email Verification Jobs
send-verification-email- Sends email verification links
- Triggered on user signup
- Sends password reset links
- Triggered on password reset request
Troubleshooting
Jobs not executing
Cause: Job dispatch endpoint not reachable. Solution: VerifyNEXT_PRIVATE_INTERNAL_WEBAPP_URL is correct:
Jobs stuck in PROCESSING state
Cause: Job handler crashed or timed out. Solution:- Check application logs for errors
-
Manually mark jobs as FAILED:
High database load from jobs
Cause: Too many jobs executing concurrently. Solution:- Increase database resources
- Optimize job handlers to use fewer queries
- Consider switching to Inngest for better concurrency control
Duplicate cron job executions
Cause: Multiple instances creating the same cron job. Solution: This shouldn’t happen with the local provider’s deterministic IDs. If it does:- Check database logs for unique constraint violations
- Verify all instances use the same
NEXT_PRIVATE_INTERNAL_WEBAPP_URL - Ensure system clocks are synchronized (NTP)
Performance Optimization
Reduce Job Latency
For the local provider, job latency depends on:- Network latency to the job endpoint
- Database performance for job updates
- Job handler execution time
- Use
NEXT_PRIVATE_INTERNAL_WEBAPP_URLwith a local IP (not external domain) - Optimize database queries in job handlers
- Use connection pooling
Handle High Volume
For deployments with >10,000 jobs/day:-
Monitor database size: Clean up old jobs periodically
- Scale horizontally: Deploy multiple instances
- Consider Inngest: For >100,000 jobs/month
Security Considerations
Job Endpoint Security
The local provider uses signed requests to secure the job endpoint:- Each request includes a signature (
X-Job-Signatureheader) - Signature is verified before job execution
- Prevents unauthorized job triggering
Sensitive Data in Jobs
Job payloads are stored in the database. Avoid storing sensitive data:Monitoring and Observability
Metrics to Track
-
Job Success Rate
-
Average Job Duration
-
Retry Rate
Alerting
Set up alerts for:- Jobs failing repeatedly
- Jobs stuck in PROCESSING
- High retry rates
- Cron jobs not running
Migrating Between Providers
Local to Inngest
- Set up Inngest account and get event key
- Update environment variables:
- Deploy the updated configuration
- Verify jobs are appearing in Inngest dashboard
- Monitor for any issues
Inngest to Local
- Update environment variables:
- Deploy the updated configuration
- New jobs will use the local provider
- Existing Inngest jobs will complete normally
Best Practices
Next Steps
Environment Variables
Review all configuration options
Database Configuration
Optimize database for job storage
