A robust email delivery service with built-in reliability patterns including retries, circuit breakers, rate limiting, and failover between multiple providers.
- 📧 Multi-provider email delivery (Primary + Secondary)
- 🔄 Automatic failover between providers
- 🔁 Configurable retry mechanism with exponential backoff
- ⚡ Circuit Breaker implementation
- 🚦 Rate limiting
- 🔑 Idempotency support
- 📊 Status tracking for all sent emails
- 📝 Detailed logging
- 🔍 Email status lookup
⚠️ Provider health monitoring
graph TD
A[Client] -->|Send Request| B[Email Service]
B --> C{Primary Provider}
C -->|Success| D[Return Success]
C -->|Failure| E[Circuit Breaker]
E -->|Open| F{Secondary Provider}
F -->|Success| D
F -->|Failure| G[Return Error]
B --> H[Rate Limiter]
B --> I[Idempotency Check]
Backend:
- Node.js
- TypeScript
- Express
Reliability Patterns:
- Circuit Breaker
- Exponential Backoff Retry
- Token Bucket Rate Limiting
- Idempotency Keys
- Simple logging
- Fallback mechanism to switch providers
Testing:
- Jest
- ts-jest
- Supertest
- Node.js v16+
- npm/yarn
- TypeScript
-
Clone the repository:
git clone https://github.com/jasjeev013/email-service.git cd email-service -
Install dependencies:
npm install
-
Configure environment variables (create
.envfile):PORT=3000 // Optional RATE_LIMIT_WINDOW_MS=60000 // Optional RATE_LIMIT_MAX=10 // Optional
Start the development server:
npm run devThe service will be available at:
http://localhost:3000
Run unit tests:
npm testRun tests with coverage:
npm test -- --coverageTest watch mode:
npm run test:watch- Provider failure scenarios
- Rate limiting behavior
- Circuit breaker state transitions
- Idempotency checks
- Retry logic validation
-
Install Vercel CLI:
npm install -g vercel
-
Deploy:
vercel
Build the Docker image:
docker build -t email-service .Run the container:
docker run -p 3000:3000 email-service- Fork the project
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
```
