Dapr

Distributed Application Runtime — a CNCF project that provides a set of portable, event-driven building blocks for distributed applications via a sidecar architecture, decoupling application code from infrastructure choices.

Problem

Building distributed microservices requires solving the same problems repeatedly: reliable pub/sub messaging, distributed state management, service invocation with retries, secret management, workflow orchestration. Each cloud provider has their own services for these, creating vendor lock-in. How do you build portable distributed applications without rewriting the infrastructure layer for each environment?

Solution / Explanation

Dapr runs as a sidecar process alongside each application instance. Applications communicate with Dapr via a local HTTP or gRPC API, and Dapr handles the interaction with the underlying infrastructure components (which are pluggable).

Application ──HTTP/gRPC──► Dapr Sidecar ──► Redis (state)
                                       ──► Kafka (pub/sub)
                                       ──► Vault (secrets)
                                       ──► Azure Service Bus (pub/sub)

The application only knows the Dapr API. Swap Redis for DynamoDB by changing Dapr configuration — zero code changes.

Building Blocks

Building BlockPurposeExample Use
Pub/SubReliable async messagingOrder events → multiple consumers
State ManagementDistributed key-value stateSession state, shopping cart
Service InvocationService-to-service calls with retries + tracingSynchronous API calls
Bindings (Input)Trigger app from external eventS3 upload triggers processing
Bindings (Output)Send events to external systemsSend email on order completion
SecretsAccess secrets from any storeDB passwords, API keys
ActorsVirtual actor modelPer-user or per-entity state machines
WorkflowDurable multi-step orchestrationOrder fulfillment process
ConfigurationRead/watch app configurationFeature flags, dynamic settings
CryptographyEncrypt/decrypt/sign dataPII protection

Workflow Building Block

Dapr Workflow provides durable, fault-tolerant workflow orchestration comparable to Azure Durable Functions or Temporal. Workflows are defined as code, survive process restarts, and have built-in retry and compensation:

workflow OrderWorkflow(orderId):
    inventory ← call ReserveInventory(orderId)
    if inventory.success:
        payment ← call ProcessPayment(orderId)
        call ScheduleShipping(orderId)

Actor Model Integration

Dapr’s Actor building block implements the virtual actor pattern: actors are created on demand, activated on a specific host node, and deactivated when idle. State is automatically persisted to the configured state store.

Pluggable Components

All Dapr building blocks use a component model — swap infrastructure without code changes:

Building BlockComponent Options
StateRedis, Azure CosmosDB, DynamoDB, Cassandra, PostgreSQL
Pub/SubKafka, RabbitMQ, Azure Service Bus, AWS SNS/SQS, Google Pub/Sub
SecretsVault, Azure Key Vault, AWS SSM, Kubernetes secrets

When to Use

Strong fit:

  • Cloud-agnostic microservices (need to run on multiple clouds or on-prem)
  • Teams want to avoid vendor lock-in for messaging/state
  • Event-driven architecture without direct dependency on specific broker
  • Workflow orchestration across microservices

Weaker fit:

  • Single-cloud, fully managed infrastructure (AWS-native stack already solves these problems)
  • Simple applications where the sidecar overhead isn’t justified
  • Extreme performance requirements where sidecar RPC adds too much latency

Trade-offs

BenefitCost
Cloud-agnostic portabilitySidecar adds latency and operational complexity
Infrastructure swap without code changesDapr is another system to operate and upgrade
Unified building blocks reduce custom codeDapr API is a new abstraction layer to learn
CNCF backed; active ecosystemStill relatively young; breaking changes possible
Built-in observability (OpenTelemetry integration)Debugging requires understanding sidecar interactions