Back to blog
Webhook vs. Polling: Why JunkMail Chose Real-Time (And Why You Should Too)

Webhook vs. Polling: Why JunkMail Chose Real-Time (And Why You Should Too)

Discover the technical architecture behind JunkMail. How we handle thousands of emails per second without ever making your test scripts wait.

By Engineering Team1/7/2026

In the world of development, there is a promise that is often broken: "real-time."

How many times have you coded a script that needs to wait for an external event (like an incoming email), only to end up writing a while(true) loop that bombards an API every two seconds? That’s called Polling. And in 2026, it’s a bit like checking your physical mailbox every 5 minutes to see if the mailman has come.

At JunkMail, we built our infrastructure on the opposite principle: the Webhook.

Let's dive under the hood to understand why this choice changes everything for your tests and your applications.

Polling: The Silent Resource Drain

Polling is the "brute force" method. Your application asks JunkMail: "Do I have mail? No. How about now? No. Now? Still no."

Why it's a bad idea:

  1. Wasted Resources: Every request consumes bandwidth and CPU on both your server and ours.
  2. Artificial Latency: If you poll every 10 seconds, you could receive the email with a 9.9-second delay. In a CI/CD pipeline of 500 tests, that delay becomes unacceptable.
  3. Cost: APIs often limit the number of requests per minute (Rate Limiting). Polling makes you hit those limits very (too) quickly.

Webhook: "Don't Call Us, We'll Call You"

The Webhook is the elegant approach. You give JunkMail a URL (your endpoint), and we stay silent. As soon as an email arrives and passes our filters, we "push" the data to you instantly.

The advantages are massive:

  • Instant Responsiveness: As soon as the Haraka SMTP server finishes receiving the mail, it’s at your doorstep in milliseconds.
  • Efficiency: A single HTTP request only when necessary.
  • Scalability: Your server can handle thousands of incoming emails without having to maintain complex waiting loops.

The JunkMail Architecture: A Four-Part Symphony

To make this real-time possible, JunkMail uses a tech stack optimized for pure performance.

1. Reception (Haraka SMTP)

We use Haraka, an ultra-fast SMTP server written in Node.js. Unlike traditional servers (Postfix, Exim), Haraka is event-driven. it allows us to intercept the email as it arrives and trigger our scripts immediately.

2. The Brain (NestJS & Redis)

Once the mail is received, it’s sent to our NestJS API. The content is stored ephemerally in Redis, an in-memory database. Why Redis? Because writing to a hard drive is too slow for our standards.

3. Notification (Webhooks & WebSockets)

This is where the magic happens.

  • For Your Tests: If you’ve configured a Webhook, our system sends a POST request to your URL with the JSON content of the mail.
  • For Your Dashboard: We use WebSockets (Socket.io). This is why your JunkMail interface blinks and displays the email without you having to refresh the page.

4. Cleanup (Cron & TTL)

Data is alive, but it must die. We use Redis's TTL (Time To Live) mechanisms and scheduled tasks (Cron) to ensure your emails truly vanish after 24h or 30 days, depending on your plan.


Use Case: Why Devs Love Our Webhooks

Imagine you’re testing a payment flow that sends an invoice.

Without Webhook: Your Playwright test has to loop, handle timeouts, and potentially miss the email if the network flinches. Your code is littered with sleep(5000).

With JunkMail Webhook: Your test launches a tiny temporary HTTP server (via a library like express or msw). It configures the webhook URL on JunkMail. It simply waits for the POST request. As soon as it arrives, the test continues. Result: Your tests are 5x faster and 100% stable.

Conclusion

JunkMail’s architecture wasn't designed to just "store mail." It was designed as a real-time data infrastructure.

By choosing Webhooks over Polling, we offer you the most precise tool on the market for your automations. Because we know that your time is the most valuable resource in your stack.

Ready to shift gears? Set up your first Webhook on JunkMail Business.