π What is Dapr?
Dapr (Distributed Application Runtime) is a portable, event-driven runtime that helps developers build microservices-based, cloud-native applications. Dapr provides building blocks like:
- Service invocation (e.g., gRPC/HTTP between services)
- State management
- Pub/Sub messaging
- Secrets management
- Bindings (to external systems like Kafka, databases, etc.)
- Middleware (e.g., for observability, authentication, transformation)
These building blocks can be accessed via HTTP or gRPC, and Dapr runs as a sidecar next to your app (in Kubernetes or on a VM/host).
π§© What is WebAssembly (Wasm)?
WebAssembly (Wasm) is a binary instruction format designed to be:
- Portable across environments
- Fast and safe to run in a sandbox
- Language-neutral (you can compile from C, Rust, Go, etc.)
Wasm can be used not just in browsers but also on the server, edge devices, and now β inside Dapr!
π How Dapr and Wasm Work Together
Dapr supports Wasm-based middleware, meaning you can run lightweight, user-defined logic written in WebAssembly modules inside the Dapr HTTP pipeline.
Use case: You want to run logic before or after an HTTP request is processed, like:
- Validating headers
- Logging metadata
- Modifying requests or responses
- Doing lightweight A/B routing
You can write that logic in Rust, AssemblyScript, or any Wasm-supported language, compile it to .wasm
, and register it as middleware in Dapr.
π οΈ How It Works in Practice
Write the Middleware
Create a WebAssembly module that implements a simple interface defined by proxy-wasm.Register It in Dapr
You define amiddleware.wasm
component like:
apiVersion: dapr.io/v1alpha1
kind: Middleware
metadata:
name: my-wasm-middleware
namespace: default
spec:
type: middleware.wasm
version: v1
metadata:
- name: url
value: "file:///components/my-middleware.wasm"
- Attach It to Your App When configuring Dapr sidecars in Kubernetes or CLI, you link the middleware to an HTTP pipeline.
apiVersion: dapr.io/v1alpha1
kind: Configuration
metadata:
name: myconfig
spec:
httpPipeline:
handlers:
- name: my-wasm-middleware
type: middleware.wasm
π― Benefits
- Portability: Wasm runs the same everywhere β ideal for edge/cloud/hybrid.
- Performance: Wasm is compiled, fast, and resource-efficient.
- Security: Wasm runs in a sandbox β safer than native code.
- Language Flexibility: You can write your logic in Rust, Go, etc.
π When to Use Dapr + Wasm
Use Dapr + Wasm middleware when you need custom, fast, portable logic as part of your microservices' HTTP handling, especially in edge/IoT/cloud-native apps.
https://docs.dapr.io/reference/components-reference/supported-middleware/middleware-wasm/
Top comments (0)