Best Practices
Job Design
1. Keep Jobs Small and Focused
# ✅ Good - focused job
class SendWelcomeEmailJob(Job):
async def handle(self):
await send_email(self.user_id, "welcome")
# ❌ Bad - doing too much
class UserSignupJob(Job):
async def handle(self):
await send_email()
await create_profile()
await setup_billing()
await send_sms()2. Make Jobs Idempotent
3. Set Appropriate Timeouts
4. Use Descriptive Names
Queue Organization
5. Use Different Queues for Different Priorities
6. Organize by Function
Data Handling
7. Don't Store Large Payloads
8. Handle Sensitive Data Carefully
9. Validate Data Before Dispatching
Error Handling
10. Always Implement failed()
11. Use Appropriate Retry Strategies
12. Log Appropriately
Monitoring
13. Monitor Queue Size
14. Track Processing Time
15. Monitor Failure Rates
Performance
16. Use Bulk Operations
17. Choose the Right Driver
18. Scale Workers Appropriately
Deployment
19. Use Process Managers
20. Regular Maintenance
Testing
21. Test Jobs in Isolation
22. Test with Limited Retries
Common Anti-Patterns
❌ Don't Block Workers
❌ Don't Chain Jobs Inside handle()
❌ Don't Store Job State in Class Variables
Checklist
Summary
Next Steps
Last updated