Overview
Follow these best practices to build production-ready integrations that are secure, reliable, and performant.
Security: Protect credentials and sensitive data.
Error Handling: Handle failures gracefully with retries.
Performance: Optimize API usage and respect rate limits.
Reliability: Build resilient integrations that handle edge cases.
Authentication & Security
Credential Management
Never hardcode credentials Don’t do this:
Do this instead:
Use environment variables or secure vault services
Never commit credentials to version control
Add .env to your .gitignore file
Rotate credentials regularly Recommended rotation schedule:
API tokens: Every 90 days
OAuth2 access tokens: Refresh proactively (every 25 days)
Immediately rotate if compromise is suspected
Why rotate?
Employees leave
Credentials can be accidentally exposed
Security vulnerabilities can be discovered
Use the least privilege principle Only request the scopes and permissions you absolutely need:
Too broad:
Appropriate:
Create separate tokens for different integrations
Review and remove unused scopes
Use organization tokens only when necessary
Always use HTTPS All API requests must use HTTPS:
Incorrect:
Correct:
HTTPS encrypts data in transit
Protects against man-in-the-middle attacks
Required by Deel API (HTTP requests will fail)
Webhook Security
When receiving webhooks, always verify the signature:
Error Handling & Retries
Implement Exponential Backoff
Retry failed requests with exponential backoff to avoid overwhelming the API:
Handle Specific Error Codes
Different errors require different handling strategies:
Validate Request Data
Always validate data before sending to the API:
Rate Limiting
Deel enforces a rate limit of 5 requests per second per organization . This limit is shared across all API tokens in your organization.
Important : Rate limits are organization-wide and Deel does not return rate limit headers. Proactive rate limiting through request queuing is essential.
Key Strategies
Request Queuing: Always implement request queuing to stay within limits.
Space Out Requests: Avoid bursts—spread requests over time.
Cache Responses: Reduce unnecessary API calls.
Centralize Requests: Coordinate all API calls across your organization.
Quick example:
Idempotency
Use idempotency keys for POST and PATCH requests to safely retry without creating duplicates.
Idempotency keys prevent duplicate resources when retrying failed requests. Responses are cached for 24 hours.
Quick example:
Key points:
Use UUID v4 for idempotency keys
Reuse the same key when retrying
Only successful responses (2xx) are cached
Keys are valid for 24 hours
Data Handling
Validate user input Always validate and sanitize data from users:
Handle timezone conversions Always use UTC for dates and times:
Handle pagination efficiently For large datasets, use pagination properly:
Testing
Test in Sandbox First
1 Use sandbox for development Always develop and test against the sandbox environment:
2 Test error scenarios Don’t just test happy paths. Test:
Invalid authentication
Missing required fields
Rate limit handling
Network failures
Webhook signature verification
3 Validate with production-like data Use realistic test data that mirrors your production use case:
Multiple countries and currencies
Different contract types (EOR, IC, GP)
Edge cases (long names, special characters)
4 Gradual production rollout When moving to production:
Start with a small subset of users/data
Monitor error rates and performance
Gradually increase usage
Keep sandbox testing environment available
Monitoring & Logging
Log Important Events
Implement structured logging for debugging and monitoring:
What to log:
API request/response metadata (not full bodies with sensitive data)
Error conditions and stack traces
Authentication failures
Rate limit warnings
Webhook deliveries
What NOT to log:
API keys or tokens
Sensitive personal data
Full request/response bodies (unless sanitized)
Set Up Alerts
Monitor your integration health:
Error Rate Alerts: Alert when error rate exceeds threshold (e.g., >5% of requests)
Rate Limit Warnings: Alert when approaching rate limits (e.g., 80% usage)
Webhook Failures: Alert on webhook delivery failures or signature mismatches
Response Time: Alert on slow API responses (e.g., >2 seconds average)
Use connection pooling Reuse HTTP connections for better performance:
Implement request timeouts Always set reasonable timeouts:
Minimize payload size Only request the fields you need:
Use async/concurrent requests When fetching multiple independent resources:
Compliance & Privacy
Handle PII appropriately Personal Identifiable Information (PII) requires special care:
Only collect necessary PII
Encrypt PII at rest and in transit
Follow data retention policies
Implement right to deletion
Document data flows
Comply with data regulations Ensure compliance with relevant regulations:
GDPR (Europe): Data protection and privacy
CCPA (California): Consumer privacy rights
SOC 2 : Information security standards
Industry-specific regulations
Audit trail Maintain audit logs for compliance:
Summary Checklist
Before deploying to production, ensure you’ve implemented:
Next Steps