liveBook · Manning

Dapr building block API

As explained in Platform Engineering on Kubernetes

The Dapr components API is the programmatic interface for interacting with configured Dapr components such as state stores and PubSub systems.

Dapr building block APIs provide consistent interfaces for recurring distributed-application concerns while allowing platform teams to configure swappable implementations. They include service invocation, state management, publish/subscribe, secrets, bindings, actors, configuration management, and workflows. section 7.3.1

On Kubernetes, annotated deployments receive a daprd sidecar that exposes the APIs over HTTP or gRPC on localhost. Component resources connect those APIs to backing infrastructure such as Redis or Kafka. section 7.3.2

A developer workflow typically combines declarative infrastructure with SDK calls:

  • Annotate the deployment with dapr.io/enabled and dapr.io/appid so the control plane enables Dapr for the application. section 7.3.2
  • Define a component resource naming the API implementation and its connection metadata, such as a Redis state store or Kafka PubSub component. section 7.3.2 section 7.3.5
  • Call the local API through the Dapr Go SDK to get or save state and publish events without directly depending on Redis or Kafka clients. section 7.3.5
  • Declare subscriptions that connect a PubSub topic to an application route and optionally scope delivery to named services. section 7.3.5

Conference application state and events

An Agenda service uses the Dapr client to call GetState with a statestore name and key, SaveState with serialized data, and PublishEvent with a PubSub name, topic, and event payload. section 7.3.5

Listing 7.1 Dapr Statestore component definition
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: statestore
spec:
  type: state.redis           #1
  version: v1
  metadata:
  - name: keyPrefix
    value: name
  - name: redisHost           #2
    value: redis-master:6379
  - name: redisPassword       #3
    secretKeyRef:
      name: redis
      key: redis-password
auth:
  secretStore: kubernetes

Inspect the Kubernetes Component resource that binds the Statestore API to Redis, including its host, password reference, and secret store. section 7.3.2

How Platform Engineering on Kubernetes covers it

How deep it goes
Defines API categories, sidecar delivery, annotations, component resources, subscriptions, and SDK operations, but not API internals.
Examples
Uses Redis state storage, Kafka PubSub, declarative subscriptions, and Conference application calls for reading, saving, and publishing.
What it assumes
Assumes Kubernetes deployment familiarity while teaching annotations, sidecars, component resources, subscriptions, and local API access.
What you can do after
Apply it via the Dapr Go SDK and Kubernetes resources to consume configured state and messaging capabilities.
How it connects
Connects Kubernetes, sidecar pattern, state management, publish/subscribe, service invocation, Redis, Kafka, HTTP, gRPC, and the Go SDK.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Platform Engineering on Kubernetes. The section links point to the parts of the book it draws on.