Dapr.io is an open source product, originated from Microsoft and embraced by a broad coalition of cloud suppliers (part of CNFC) and open source projects. Dapr is a runtime framework that can support any application and that especially shines with distributed applications - for example microservices - that run in containers, spread over clouds and / or edge devices.
With Dapr you give an application a "sidecar" - a kind of personal assistant that takes care of all kinds of common responsibilities. Capturing and retrieving state, publishing and consuming messages or events. Reading secrets and configuration data. Shielding and load balancing over service endpoints. Calling and subscribing to all kinds of SaaS and PaaS facilities. Logging traces across all kinds of application components and logically routing calls between microservices and other application components. Dapr provides generic APIs to the application (HTTP and gRPC) for calling all these generic services – and provides implementations of these APIs for all public clouds and dozens of technology components. This means that your application can easily make use of a wide range of relevant features - with a strict separation between the language the application uses for this (generic, simple) and the configuration of the specific technology (e.g. Redis, MySQL, CosmosDB, Cassandra, PostgreSQL, Oracle Database, MongoDB, Azure SQL etc) that the Dapr sidecar uses. Changing technology does not affect the application, but affects the configuration of the Sidecar. Dapr can be used from applications in any technology - from Java and C#/.NET to Go, Python, Node, Rust and PHP. Or whatever can talk HTTP (or gRPC).
In this Code Café I will introduce you to Dapr.io. I will show you what Dapr can do for you (application) and how you can Dapr-izen an application. I'll show you how an asynchronously collaborative system of microservices - implemented in different technologies - can be easily connected to Dapr, first to Redis as a Pub/Sub mechanism and then also to Apache Kafka without modifications. Then we do - with the interested parties - also a hands-on in which you will apply Dapr yourself . In a short time you get a good feel for how you can use Dapr for different aspects of your applications. And if nothing else, Dapr is a very easy way to get your code with Kafka, S3, Redis, Azure EventGrid, HashiCorp Consul, Twillio, Pulsar, RabbitMQ, HashiCorp Vault, AWS Secret Manager, Azure KeyVault, Cron, SMTP, Twitter, AWS SQS & SNS, GCP Pub/Sub and dozens of other technology components talk.
2. Classificatie: vertrouwelijk
Demo
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
dapr run --app-id myapp --dapr-http-port 3500
http
port 3500
myapp
default-components.yaml
Redis
Zipkin
tracing
Zipkin
Redis
state store
pubsub broker
Redis
state: redis
pubsub: redis
OpenTelemetry:
3. Classificatie: vertrouwelijk
Demo
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
curl -X POST -H "Content-Type: application/json"
-d '[{ "key": "name", "value": "Bruce Wayne"}]'
http://localhost:3500/v1.0/state/statestore
http
port 3500
myapp
default-components.yaml
Redis
Zipkin
tracing
Zipkin
Redis
state store
pubsub broker
Redis
statestore
pubsub
POST
key: name
value: Bruce Wayne
4. Classificatie: vertrouwelijk
Demo
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
curl -X POST -H "Content-Type: application/json"
-d '[{ "key": "name", "value": "Bruce Wayne"}]'
http://localhost:3500/v1.0/state/statestore
http
port 3500
myapp
default-components.yaml
Redis
Zipkin
tracing
Zipkin
Redis
state store
pubsub broker
Redis
statestore
pubsub
POST
key: name
value: Bruce Wayne
key: name
value:
Bruce
Wayne
5. Classificatie: vertrouwelijk
Demo
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
curl http://localhost:3500/v1.0/state/statestore/name
http
port 3500
myapp
default-components.yaml
Redis
Zipkin
tracing
Zipkin
Redis
state store
pubsub broker
Redis
statestore
pubsub
GET
key: name
value:
Bruce
Wayne
6. Classificatie: vertrouwelijk
Demo
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
curl http://localhost:3500/v1.0/state/statestore/name
http
port 3500
myapp
default-components.yaml
Redis
Zipkin
tracing
Zipkin
Redis
state store
pubsub broker
Redis
statestore
pubsub
GET
key: name
value: Bruce Wayne
“Bruce Wayne”
7. Classificatie: vertrouwelijk
Demo
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
http
myapp
app-components.yaml
Redis
Zipkin
tracing
Zipkin
Redis
state store
pubsub broker
Redis
My App
Application
http
8. Classificatie: vertrouwelijk
Hypothetical Demo
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
http
myapp
app-components.yaml
Redis
Zipkin
tracing
Zipkin
Redis
state store
pubsub broker
Redis
My App
Application
MySQL
database
http
11. Classificatie: vertrouwelijk
The Microservices Platform
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
power cooling
rack
space
physical real estate
IAM
Certificate
Management
Vulnerability
Scanning
Logging
Monitoring Auditing
Cloud Usage
Analysis
Resource
Manager
APIs
Cloud
Events
Notifications Cloud Guard
Tagging
Search
Serverless
Functions
Container
engine
API
Gateway
Load
Balancer
Container
Registry
Artifact
Repository
Job
Scheduling Build & Deploy
Pipelines
Code
Repository
Web Application
Firewall
CDN
Virtual
Machines
API
µ
12. Classificatie: vertrouwelijk
The Microservices Platform
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
power cooling
rack
space
physical real estate
IAM
Certificate
Management
Vulnerability
Scanning
Logging
Monitoring Auditing
Cloud Usage
Analysis
Resource
Manager
APIs
Cloud
Events
Notifications Cloud Guard
Tagging
Search
SQL
Database Serverless
Functions
Container
engine
Vault
API
Gateway
Load
Balancer
Message/
Event Broker
Data
Lake
Container
Registry
Artifact
Repository
Job
Scheduling Build & Deploy
Pipelines
NoSQL
Database
Data
Cache
Code
Repository
Web Application
Firewall
CDN
Virtual
Machines
File Storage
API
µ
13. Classificatie: vertrouwelijk
The Microservices Platform
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
power cooling
rack
space
physical real estate
IAM
Certificate
Management
Vulnerability
Scanning
Logging
Monitoring Auditing
Cloud Usage
Analysis
Resource
Manager
APIs
Cloud
Events
Notifications Cloud Guard
Tagging
Search
SQL
Database Serverless
Functions
Container
engine
Vault
API
Gateway
Load
Balancer
Message/
Event Broker
Data
Lake
Container
Registry
Artifact
Repository
Job
Scheduling Build & Deploy
Pipelines
NoSQL
Database
Data
Cache
Code
Repository
Web Application
Firewall
CDN
Virtual
Machines
File Storage
API
µ
Zipin
14. Classificatie: vertrouwelijk
What do most microservices do?
• Store and retrieve state
• Read runtime secrets and configuration values
• Publish “observability data”
• Subscribe to event topic and handle incoming events
• Publish events to event topic
• Interact with other microservices
• Invoke external services
• Run microservice specific business logic
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
This requires quite a bit of
repetitive “plumbing” tied to
specific technologies
– not meaningful effort
[from a business functionality
perspective]
16. Classificatie: vertrouwelijk
Dapr
• Runtime
• Personal Assistant for Applications and Microservices
• Distributed Application Runtime
• Microservice architecture
• Decoupling
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
17. Classificatie: vertrouwelijk
Dapr.io
• Launched by Microsoft (2019)
• Application runtime framework –
supporting cloud native and serverless
• Every application gets a uniform Personal Assistant
that takes care of common tasks
• remember (take note and reproduce)
• keep log
• restrict access
• handle incoming
• route outgoing
• interact with
other PAs (and
their apps)
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
Application
Microservice or
Monolith
Personal
Assistant
(Dapr)
Personal
Assistant
(Dapr)
Personal
Assistant
(Dapr)
Personal
Assistant
(Dapr)
Personal
Assistant
(Dapr)
Personal
Assistant
(Dapr)
18. Classificatie: vertrouwelijk
Dapr.io
• Personal Assistant is Dapr Side Car
• companion process or side car container in Kubernetes Pod
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
My App Dapr API
HTTP/gRPC
Application
Dapr sidecar
22. Classificatie: vertrouwelijk
Dapr state API
Save state
POST /v1.0/state/corpdb
Retrieve state
GET /v1.0/state/corpdb/mystate
Delete state
DELETE /v1.0/state/corpdb/mystate
Get bulk state
POST /v1.0/state/corpdb/bulk
Submit multiple state transactions
POST /v1.0/state/corpdb/transaction
corpdb-redis.yaml
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: corpdb
spec:
type: state.redis
version: v1
metadata:
- name: redisHost
value: redis-master.default.svc.cluster.local:6379
- name: redisPassword
secretKeyRef:
name: redis-secret
key: redis-password
23. Classificatie: vertrouwelijk
Dapr state API
Save state
POST /v1.0/state/corpdb
Retrieve state
GET /v1.0/state/corpdb/mystate
Delete state
DELETE /v1.0/state/corpdb/mystate
Get bulk state
POST /v1.0/state/corpdb/bulk
Submit multiple state transactions
POST /v1.0/state/corpdb/transaction
corpdb-cosmosdb.yaml
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: corpdb
spec:
type: state.azure.cosmosdb
version: v1
metadata:
- name: url
value: corpdb.documents.azure.com
- name: masterKey
secretKeyRef:
name: master-key
key: cosmos-key
- name: database
value: orders
- name: collection
value: processed
24. Classificatie: vertrouwelijk
HTTP API gRPC API
Microservice building blocks
Service-
to-service
invocation
State
management
Publish
and
subscribe
Resource
bindings
and triggers
Actors Observability Secrets Extensible
25. Classificatie: vertrouwelijk
Standard APIs accessed over http/gRPC protocols from
user service code
Runs as local “side car library” dynamically loaded
at runtime for each service
HTTP API gRPC API
Any language and framework
Application code
Microservices written in
Any code or framework…
Service-
to-service
invocation
State
management
Publish
and
subscribe
Resource
bindings
and triggers
Actors Observability Secrets Application
Configuration
26. Classificatie: vertrouwelijk
HTTP API gRPC API
Any cloud or edge infrastructure
Application code
Microservices written in
Any code or framework…
Service-
to-service
invocation
State
management
Publish
and
subscribe
Resource
bindings
and triggers
Actors Observability Secrets Application
Configuration
Hosting infrastructure
On-Premises
Azure Arc
28. Classificatie: vertrouwelijk
Service invocation
Service A
My App
mDNS
Multicast DNS component for
service discovery
mTLS encryption
POST
http://localhost:3500/v1.0/invoke/servicea/method/neworder
{"data":"Hello World"}
POST
http://10.0.0.2:8000/neworder
{"data":"Hello World"}
29. Classificatie: vertrouwelijk
Publish and subscribe
Service B
My App Redis
Cache
Service A
POST
http://localhost:3500/v1.0/publish/orders/processed
{"data":"Hello World"}
POST
http://10.0.0.2:8000/orders
http://10.0.0.4:8000/factory/orders
{"data":"Hello World"}
33. Classificatie: vertrouwelijk
Host/Pod
Stateful, objects of
storage and compute
Dapr Actor features:
Distribution and failover
Turn-based concurrency
State management
Timers
Reminders
Host/Pod
Video Game
Enemy
Virtually identical to Service Fabric Reliable Actors
Virtual actors
34. Classificatie: vertrouwelijk
Actor A
Actor C
My
Actor
Pod 1
Actor B
Actor F
Actor E
Actor G
Virtual actors
My App
POST
http://localhost:3500/v1.0/actors/MyActor/A/method/update
{"speed":"1"}
Dapr actor placement
service
Placement
Actor Z
Actor X
My
Actor
Pod 2
Actor Y
Actor U
Actor V
Actor T
36. Classificatie: vertrouwelijk
Metrics
Dapr Metrics features:
Call latency
CPU/memory usage
Error rates
Sidecar injection failures
System health
Built-in monitoring capabilities to
understand the behavior of the
Dapr sidecar and system services
37. Classificatie: vertrouwelijk
Application Configuration Settings (preview)
Centralized management of configuration settings such as endpoints, hostnames,
filesystem locations, feature toggles.
Applications can consume configuration values and subscribe to change events.
38. Classificatie: vertrouwelijk
Dapr hosting environments
• Get started with dapr init -k
• Fully managed Dapr control plane
• Deploys dashboard, placement, operator,
sentry, and injector pods
• Automatically inject Dapr sidecar into
all annotated pods
• Upgrade with dapr upgrade or Helm
• Get started with dapr init
• Easy setup with Docker images
• Sets up placement, Zipkin, Redis
• slim-init available without Docker
• Run any application with Dapr sidecar
using dapr run
Self-hosted
39. Classificatie: vertrouwelijk
Dapr in self-hosted Docker mode
Local dev machine or virtual machine
Zipkin
tracing
Zipkin
Redis
state store
Redis
My App
State Stores
PubSub
Brokers
Secret Stores
Bindings
& Triggers
Observability
Dapr Components
dapr run myapp
Use components
Launch application
Launch sidecar process
Set env variables
Save and retrieve state
Publish and subscribe to messages
Send distributed tracing
40. Classificatie: vertrouwelijk
Dapr in self-hosted Docker mode – add MySQL Database
Local dev machine or virtual machine
Zipkin
tracing
Zipkin
MySQL
database
Redis
state store
Redis
myotherapp
dapr run --app-id myotherapp --dapr-http-port 3510 --components-path .
Launch application
Launch sidecar process
Set env variables
Save and retrieve state
mysql-statestore.yaml
41. Classificatie: vertrouwelijk
Dapr on Kubernetes
Any cloud or edge infrastructure
Pod
Actor
partition
placement
Placement
Pod
Dapr
runtime
injector
Injector
Pod
Cert authority
and identity Sentry
Pod
Update
component
changes
Operator
Pod
My App
Kubelet Use components
Inject Dapr sidecar
into annotated pods
Inject env variables
Manage mTLS
between services
Assign spiffe identity
Create mapping table of
actor instances to pods
Manage component updates
Manage Kubernetes
service endpoints
Readiness and Liveness
probe on healthz API to
determine Dapr health state
State Stores
Pub/Sub
Brokers
Secret Stores
Bindings
& Triggers
Observability
Dapr Components
Operator
Deploys and
manages Dapr
42. Classificatie: vertrouwelijk
Dapr and service meshes
Service Mesh
Operator
Hosting infrastructure
Application code
Any code or
framework…
Traffic splitting
Traffic routing
Distributed tracing
Resiliency
Metrics
mTLS
Service-to-service
invocation
State
management
Publish and
subscribe
Secrets
Resource bindings
and triggers
Actors
Developer
43. Classificatie: vertrouwelijk
Dapr and Node Applications
• HTTP (or gRPC) with Dapr SideCar
• easier yet: Node SDK for Dapr
• Leverage Dapr and its building blocks for
• simple state management
• simple publication of messages
• subscription to incoming messages
• retrieving secrets
• retrieving configuration data
• invoking external services (database, message broker, store, API)
• register as listener to inbound requests and messages for external
services
• decoupled interaction between microservices – implemented in
potentially very different languages
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
components.yaml
sidecar (the personal assistant)
Node SDK
for Dapr
Observability
Prometheus AppInsights Jaeger
Zipkin
Bindings
& Triggers
GCP
Storage
AWS
S3 Kafka
Azure
Storage Twilio
State
Stores
Firebase Cassandra
Redis
Azure
CosmosDB
AWS
DynamoDB
Secret
Stores
AWS
Secrets Manager
Azure
KeyVault
GCP
Secret Manager
HashiCorp
Vault
Kubernetes
Secret
PubSub
Brokers
Redis
AWS
SQS
Azure
Service Bus
RabbitMQ
GCP
Pub/Sub
44. Classificatie: vertrouwelijk
Observability
Prometheus AppInsights Jaeger
Zipkin
Bindings
& Triggers
State
Stores
Secret
Stores
PubSub
Brokers
Dapr Architecture
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
Dapr main
state store
interface
pub/sub
interface
binding
interface
secret
interface
register all
components
(per type)
observable
interface
do something for me – store
or retrieve state, subscribe
to topic (and callback with
messages), invoke service,
retrieve secret
components.yaml
45. Classificatie: vertrouwelijk
State Management with Dapr from Node application
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
sidecar (the personal assistant)
Node SDK
for Dapr
State Store
components
set & get state
components.yaml
State
Stores
state store
interface
46. Classificatie: vertrouwelijk
State Management with Dapr from Node application
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
sidecar (the personal assistant)
Node SDK
for Dapr
State Store
components
set & get state
components.yaml
State
Stores
state store
interface
connect to
sidecar
retrieve
state
setstate
47. Classificatie: vertrouwelijk
State Management with Dapr from Node application -
switch to MySQL state store with configuration change
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
sidecar (the personal assistant)
Node SDK
for Dapr
State Store
components
set & get state
components.yaml
State
Stores
state store
interface
connect to
sidecar
retrieve
state
setstate
48. Classificatie: vertrouwelijk
State Management with Dapr from any application
- either through SDK or using HTTP or gRPC
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
sidecar (the personal assistant)
SDK for
Dapr
State Store
components
set & get state
components.yaml
State
Stores
state store
interface
49. Classificatie: vertrouwelijk
Pub/Sub with Dapr from Node applications
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
sidecar (the personal assistant)
Node SDK
for Dapr
Pub/Sub
components
publish message
components.yaml
PubSub
Brokers
pub/sub
interface
Node SDK
for Dapr
components.yaml
subscribe on topic
with handler function
message sent to handler
50. Classificatie: vertrouwelijk
Pub/Sub with Dapr from Node applications
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
sidecar (the personal assistant)
Node SDK
for Dapr
Pub/Sub
components
publish message
components.yaml
PubSub
Brokers
Node SDK
for Dapr
components.yaml
subscribe on topic
with handler function
message sent to handler
pub/sub
interface
publish
message
51. Classificatie: vertrouwelijk
Pub/Sub with Dapr from Node applications
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
sidecar (the personal assistant)
Node SDK
for Dapr
Pub/Sub
components
publish message
ponents.yaml
PubSub
Brokers
Node SDK
for Dapr
components.yaml
pub/sub
interface
subscribe
on topic
message sent
to handler
52. Classificatie: vertrouwelijk
Pub/Sub with Dapr from Node applications
Replace Redis by Apache Kafka
Microservices in real life – with Node & Dapr.io
sidecar (the personal assistant)
Node SDK
for Dapr
Pub/Sub
components
publish message
to topic
components.yaml
PubSub
Brokers
pub/sub
interface
Node SDK
for Dapr
components.yaml
subscribe on topic
with handler function
message sent to handler
9094
9093
9092
test-topic
53. Classificatie: vertrouwelijk
Asynchronous Interaction between Microservices
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
Front App
http
State
Stores
PubSub
Brokers
Node App
get get & set
publish
subscribe
consume
name = John
54. Classificatie: vertrouwelijk
Telemetry Observation in Zipkin
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
greeter
http
State
Stores
PubSub
Brokers
name-processor
get get & set
publish
subscribe
consume
name = John
Telemetry
Data
55. Classificatie: vertrouwelijk
Telemetry Observation in Zipkin
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
Telemetry
Data
Front App
http
State
Stores
PubSub
Brokers
Node App
get get & set
publish
subscribe
consume
name = John
56. Classificatie: vertrouwelijk
Hands On
In a Linux compatible environment with Docker CLI set up
• Download and Install Dapr.io
• with out of the box state management and pub/sub based on Redis and
telemetry observation by Zipkin
• Run Dapr Sidecar
• Explore Dapr State Management APIs
• from the command line (cURL HTTP calls)
• Run MySQL container and have Dapr manage state in a MySQL database
• Explore Dapr Telemetry collection and presentation in Zipkin
• Explore Node and Dapr
• add state management to Node application – through Dapr sidecar
• implement pub/sub for Node applications – through Dapr sidecar
• realize asynchronous communication between Node based microservices
through Daprized pub/sub
• Explore Telemetry for asynchronous interactions
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
57. Classificatie: vertrouwelijk
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
State
Stores
app.js
get & set
Node SDK
for Dapr
components.yaml
dapr_host,
dapr_http_port
app_port
key value
John
Monty
3
2
name,
instance count
Default, out
of the box
?name=John
Handson
58. Classificatie: vertrouwelijk
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
Handson
SomeService
Invoker SomeService
echo
Daprized Go application – has
registered an invocation
handler for operation echo
Daprized Node application –
asks its sidecar to invoke
method echo on service
SomeService
mDNS
Multicast DNS component
for service discovery
59. Classificatie: vertrouwelijk
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
Handson
SomeService
Invoker SomeService
echo
Daprized Go application – has
registered an invocation
handler for operation calculate
{ x: 3.14159,
y: 42,
z: 2.71828 }
mDNS
Multicast DNS component
for service discovery
calculate
{ "outcome":
13618.131,
"comment":
"Greetings" }
Local function
complexCalculation invokes
method calculate on remote
service SomeService
60. Classificatie: vertrouwelijk
Code Café - 4 april 2022 - Dapr - Open Source Personal Assistant voor Microservices
Handson
SomeService
echo
Daprized Go application – has
registered an invocation
handler for operation echo
OtherService
Invoker
Regular, NonDaprized Node
application – asks
SomeService’s sidecar to
invoke method echo – calling
the gRPC port of that sidecar