Get the authoritative guide on Dapr, the new distributed programming model that works with existing and new programming languages alike. Written by the model's creators, this introduction shows you how Dapr not only unifies stateless, stateful, and actor programming models but also runs everywhere--in the cloud or on the edge. Authors Haishi Bai and Yaron Schneider with Microsoft's Azure CTO team explain that with Dapr you don't need to include any SDKs or libraries in your user code. Instead, you automatically get flexible binding, state management, actor pattern, pub-sub, reliable messaging, and many more features. This book shows developers, architects, CIOs, students, and computing enthusiasts how to get started with Dapr. Copyright 4 Table of Contents 5 Preface 11 Resources 13 Conventions Used in This Book 13 O’Reilly Online Learning 14 How to Contact Us 14 Acknowledgments 15 Introduction 17 What Is Dapr? 17 A Programming Model for a Heterogeneous Environment 18 More Helpful, Less Opinionated 19 Don’t Reinvent the Wheel! 20 Unified Programming Model 21 Dapr Architecture 22 Language Support 24 Getting Started with Dapr 25 Hello, World! with Dapr Standalone Mode 25 Hello, World! with Dapr Kubernetes Mode 32 Using gRPC 37 Invoking an Application from a gRPC Client 38 Writing a gRPC Server 41 Bindings 44 Binding in Standalone Mode 45 Binding in Kubernetes Mode 48 Summary 48 Chapter 1. Services 49 The World Before Cloud 49 Cloud Promises and Challenges 50 Availability 50 Elasticity 51 Cloud Native Applications 52 Infrastructure Is Boring 53 Service Invocation 54 Name Resolution 55 Requests and Responses 57 Concurrency Control 57 Service Invocation Experiment 58 The Universal Namespace 60 Pub/Sub 61 Benefits of Message-Based Integration 61 Pub/Sub with Dapr 63 How Pub/Sub Works 64 Dapr Components 65 Dapr Configurations 66 Custom Pipelines 67 Custom Pipeline Experiment 68 OAuth 2.0 Authorization 70 Authoring a Custom Middleware 72 Distributed Tracing 73 Tracing Middleware 73 Tracing with Zipkin 74 Tracing with Azure Monitor 76 Service Operation 78 Service Deployment and Upgrade 78 OAM 79 Summary 81 Chapter 2. State 83 State Management 83 Stateless Versus Stateful 84 Why Are Stateless Services Preferred in the Cloud? 84 Challenges of Hosting Stateful Services 85 Converting Stateful Services to Stateless Services 88 Dapr State Management 88 Concurrency Model 89 Consistency Model 89 Bulk Operations and Transactions 89 Multiple State Stores 89 Retry Policies 90 The Dapr State API 90 Key Scheme 91 Get Requests 91 Set Requests 91 Delete Requests 92 Transactional Requests 92 Working with the Dapr State API 93 Data Handling Considerations 94 Data Querying and Aggregation 94 State Stores 95 Redis 95 Azure Cosmos DB 96 Etcd 97 Apache Cassandra 98 Couchbase 99 Custom State Stores 100 Implementing the State API 100 Updating the Component Registry 103 Summary 104 Chapter 3. Messaging 105 Event-Driven Programming 105 Messages Versus Events 106 Input Bindings and Output Bindings 107 Pub/Sub 108 Pub/Sub with Dapr 109 Implementing the PowerShell Script 109 Testing Pub/Sub with the Dapr CLI 110 Dapr Pub/Sub Behaviors 111 Extending Dapr Pub/Sub 111 Input and Output Bindings with Dapr 112 Using Input Bindings 113 Using Output Bindings 114 Implementing Input Bindings 114 Implementing Output Bindings 116 Autoscaling with KEDA 117 Messaging Patterns 119 The Saga Pattern 119 Content-Based Routing 121 Routing Slip 122 Smart Proxy 123 MapReduce 124 Summary 125 Chapter 4. Security 127 Securing a Distributed Application 127 Access Control 128 Data Protection 131 Secured Communication 133 Intrusion and Abnormality Detection 133 Dapr Security Features 134 Secret Stores 134 Implementing a Secret Store 136 The Secret API 137 Mutual TLS (mTLS) 137 Dapr mTLS 140 Summary 142 Chapter 5. Actors 143 The Actor Pattern 143 Modern Actor Frameworks 144 Misuse of the Actor Model 146 Dapr and Actors 147 Invoking a Dapr Actor 151 State Management 151 Timers 152 Reminders 154 Getting Started with Writing Dapr Actors for C# 155 Defining the Actor Interface 155 Implementing the Actor Interface 156 Summary 157 Chapter 6. Application Patterns 159 Cloud Native Applications 159 Cloud Environment 160 Cloud Native Applications with Dapr 164 System Integrations with Dapr 171 Distributed Workflow as Finite State Machine 172 Synchronization 173 Dapr in a Larger Ecosystem 176 Yeoman Dapr Generator 176 Dapr in Visual Studio Code 177 Dapr with ASP.NET Core 179 Dapr in a Bigger Application 180 Dapr and Service Meshes 181 Dapr on Edge 181 Summary 182 Chapter 7. Dapr’s Future 183 Capability Delivery 183 Architecture 184 Application Scenarios 186 Enhanced Actors 188 Aggregators 188 Query Interface 189 Actor Graph 189 Multiversion Actors 190 Actor Middleware 191 The Universal Namespace 191 Architecture 192 Application Scenarios 193 Dapr on Edge 194 Dapr as a Lightweight Function Runtime 194 Dapr in WebAssembly 196 Dapr as a Script 198 Other Dapr Improvements 199 Dapr Component Projection 199 Best Practices and Proven Patterns 200 Dapr Descriptor 201 Dapr to Facilitate Multiparty Computing 201 Summary 202 Index 203 About the Authors 218 Colophon 218 Get the authoritative guide to Dapr, the distributed application runtime that works with new and existing programming languages alike. Written by the model's creators, this introduction shows you how Dapr not only unifies stateless, stateful, and actor programming models but also runs everywhere—in the cloud or on the edge.Authors Haishi Bai and Yaron Schneider, both with Microsoft's Azure CTO team, explain that, with Dapr, you don't need to include any SDKs or libraries in your user code. Instead, you automatically get flexible binding, state management, the actor pattern, pub-sub, reliable messaging, and many more features. This book shows developers, architects, CIOs, students, and computing enthusiasts how to get started with Dapr.Learn the new programming model for cloud native applicationsWrite high-performance distributed applications without drilling into technical detailsUse Dapr with any language or framework to write microservices easilyLearn how Dapr provides consistency and portability through open APIs and extensible, community-driven componentsExplore how Dapr handles state, resource bindings, and pub-sub messaging to enable resilient event-driven architectures that scaleIntegrate cloud applications with various SaaS offerings, such as machine learning Get the authoritative guide on Dapr, the distributed application runtime that works with new and existing programming languages alike. Written by the model's creators, this introduction shows you how Dapr not only unifies stateless, stateful, and actor programming models but also runs everywhere-- in the cloud or on the edge. Authors Haishi Bai and Yaron Schneider with Microsoft's Azure CTO team explain that, with Dapr, you don't need to include any SDKs or libraries in your user code. Instead, you automatically get flexible binding, state management, the actor pattern, pub/sub, reliable messaging, and many more features. This book shows developers, architects, CIOs, students, and computing enthusiasts how to get started with Dapr Get the authoritative guide to Dapr, the distributed application runtime that works with new and existing programming languages alike. Written by the models creators, this introduction shows you how Dapr not only unifies stateless, stateful, and actor programming models but also runs everywherein the cloud or on the edge. Authors Haishi Bai and Yaron Schneider with Microsofts Azure CTO team explain that, with Dapr, you dont need to include any SDKs or libraries in your user code. Instead, you automatically get flexible binding, state management, the actor pattern, pub-sub, reliable messaging, and many more features. This book shows developers, architects, CIOs, students, and computing enthusiasts how to get started with Dapr.