TL;DR
Dapr (Distributed Application Runtime) provides building blocks for microservices — service invocation, state management, pub/sub, bindings, secrets, and more. It's language-agnostic, free, and runs as a sidecar next to your app.
What Is Dapr?
Dapr gives you microservice primitives via HTTP/gRPC APIs:
- Service invocation — call other services with built-in retries and mTLS
- State management — pluggable state stores (Redis, PostgreSQL, CosmosDB)
- Pub/Sub — event-driven messaging (Kafka, RabbitMQ, Redis)
- Bindings — input/output bindings to external systems
- Secrets — unified secret management API
- Actors — virtual actor pattern for stateful objects
- Free — Apache 2.0, CNCF incubating project
Quick Start
# Install Dapr CLI
curl -fsSL https://raw.githubusercontent.com/dapr/cli/master/install/install.sh | bash
# Initialize Dapr (local Docker)
dapr init
# Run your app with Dapr sidecar
dapr run --app-id my-api --app-port 3000 -- node server.js
Service Invocation
// Call another service through Dapr (automatic retries, mTLS)
const response = await fetch(
"http://localhost:3500/v1.0/invoke/order-service/method/orders",
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ item: "laptop", quantity: 1 }),
}
);
const order = await response.json();
State Management
const DAPR_URL = "http://localhost:3500";
const STORE = "statestore"; // configured in components
// Save state
await fetch(`${DAPR_URL}/v1.0/state/${STORE}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify([
{ key: "user-123", value: { name: "Alice", cart: ["item1", "item2"] } },
]),
});
// Get state
const res = await fetch(`${DAPR_URL}/v1.0/state/${STORE}/user-123`);
const user = await res.json();
Pub/Sub Messaging
// Publisher
await fetch(`${DAPR_URL}/v1.0/publish/pubsub/orders`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ orderId: "abc", amount: 99.99 }),
});
// Subscriber (your app exposes an endpoint)
import express from "express";
const app = express();
// Tell Dapr which topics to subscribe to
app.get("/dapr/subscribe", (req, res) => {
res.json([
{ pubsubname: "pubsub", topic: "orders", route: "/orders" },
]);
});
// Handle messages
app.post("/orders", (req, res) => {
console.log("Order received:", req.body.data);
res.sendStatus(200);
});
Secrets Management
// Get a secret (works with Vault, AWS Secrets Manager, K8s secrets, etc.)
const res = await fetch(
`${DAPR_URL}/v1.0/secrets/my-secret-store/database-password`
);
const secret = await res.json();
// { "database-password": "s3cur3p@ss" }
Component Configuration
# components/statestore.yaml
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: statestore
spec:
type: state.redis
version: v1
metadata:
- name: redisHost
value: localhost:6379
Dapr vs Alternatives
| Feature | Dapr | Istio | Spring Cloud | AWS App Mesh |
|---|---|---|---|---|
| Language agnostic | All | All | Java | All |
| State management | Built-in | No | No | No |
| Pub/Sub | Built-in | No | Yes | No |
| Secrets | Built-in | No | Vault | Secrets Manager |
| Local dev | Easy | Hard | Moderate | Hard |
| CNCF | Incubating | Graduated | No | No |
Resources
- Dapr Documentation
- GitHub Repository — 24K+ stars
- Quickstarts
- Component Specs
Building microservices that process web data? My Apify tools extract data from any website — integrate with Dapr for scalable data processing pipelines. Questions? Email spinov001@gmail.com
Top comments (0)