🌪 Why Tornado?
We chose Tornado as the foundation for our emailer API because of its: • High-performance Asynchronous Capabilities: Tornado’s non-blocking I/O makes it ideal for I/O-bound tasks like SMTP communication and logging. • Minimal Overhead: It gives us full control of the request/response cycle, which is ideal for building a focused microservice like our emailer. • Production-Proven: It’s been battle-tested in real-time systems and scales well under load, fitting our needs without unnecessary complexity.
⸻
📤 The Emailer API
The emailer API is a Tornado application designed for one job: sending and tracking outbound emails. • Accepts Messages via HTTP: Our internal systems (like contact forms and platform notifications) POST to this API. • Formats and Dispatches Emails: It constructs well-formatted messages and sends them using SMTP or third-party services (e.g., Mailgun, Postmark) depending on configuration. • Responds Quickly: Because of its async architecture, it responds instantly while offloading heavy tasks to the consumer.
⸻
🔁 The Consumer Service
Alongside the API, we run a separate Python consumer service that: • Subscribes to ForestMQ Topics: It listens for new email jobs sent through our internal message queue. • Handles Retries and Failures: With support for retry policies and exponential backoff, it ensures that messages are delivered even if a provider temporarily fails. • Maintains Delivery Logs: Every sent email is tracked, logged, and stored in a backend for observability and audits.
⸻
🔐 Security & Reliability • All requests are authenticated using bearer tokens across internal services. • Structured JSON validation prevents malformed payloads. • Idempotent operations ensure duplicate messages aren’t sent.
⸻
🛠 Developer Experience • Easy Testing: We use pytest for unit tests and standalone Tornado test clients for integration testing. • Simple Deployment: The API and consumer are containerized and deployed via Docker Compose using Ansible. • Real-time Logging: Logs are streamed to the platform dashboard via JSON logs, helping us monitor email delivery live.
⸻
🚀 Conclusion
By splitting email responsibilities between a dedicated API and a lightweight consumer, and leveraging Tornado’s async strengths, josef.digital has built a modular, scalable, and reliable email system. It’s fast, focused, and integrates cleanly with the rest of our platform — ensuring users receive messages at the right time, every time.