DEV Community

Bangsaen AI
Bangsaen AI

Posted on

How I Compiled C++ to WebAssembly on Cloudflare Edge to Kill Bots with 0.000ms Origin Overhead

Every web service faces the same annoying issue: AI scrapers, automated brute-force bots, and bad actors eating up origin server CPU & RAM before they even get blocked.

Traditional middleware (like PHP or Node.js security plugins) still forces your origin host to execute code just to decide whether to drop a request. That’s wasted computing resources.

I wanted to solve this with a strict rule: Zero host CPU impact on the origin server.

Here is how I compiled a C++ kernel to WebAssembly (WASM) and deployed it directly to Cloudflare Global Edge.


🏗️ The Architecture

Instead of filtering traffic at the origin, the protection layer is pushed to Cloudflare’s 300+ Edge locations globally.

[ Incoming Request ]


[ Cloudflare Global Edge ]
│ ──► [ C++ WASM Kernel Inspection ] ──► (Blocked if Bot)

Your Origin Server

Why C++ WebAssembly on the Edge?

  1. Ultra-Low Latency: Executing C++ compiled to WASM delivers sub-millisecond execution (0.000ms kernel impact).
  2. Instant Dropping: Bad actors are terminated at the nearest edge node—never reaching your actual server stack.
  3. Language Efficiency: C++ provides predictable memory usage and near-bare-metal speeds compared to standard V8 JavaScript isolates.

⚡ Try it with cURL

You can inspect the response directly from your terminal:

curl -X POST [https://bangsaen-bot-killer.bangsaen-filter.workers.dev](https://bangsaen-bot-killer.bangsaen-filter.workers.dev) \
  -H "x-bangsaen-key: YOUR_API_KEY"
Enter fullscreen mode Exit fullscreen mode

Sample JSON Response:

{
"status": "Success",
"botDetected": false,
"score": "0.0000",
"executionTime": "0.000ms"
}

🔌 What's Next & Free Tier
I've made the API gateway available with a Free Tier (100,000 requests/month) so developers can offload scraper mitigation without paying a dime or using a credit card.

🌐 Live Demo & API Key: bangsaenai.com

🔌 WordPress Users: We have submitted the official Bangsaen Filter plugin to the WordPress.org directory—currently under manual review and scheduled to launch in ~5 days!

Would love to hear your thoughts on latency optimization and edge security architecture!

Top comments (0)