Foreword
Microservices have become a popular architectural style for building distributed systems, as they allow developers to break down a monolithic application into smaller, independent components that can be developed, tested, and deployed independently. This approach offers several benefits, such as improved scalability, flexibility, and maintainability. However, building and managing microservices can also be complex, especially when it comes to tasks such as communication between services, service discovery, fault tolerance, and observability.
Dapr microservice application framework
Dapr is an open-source, portable runtime that aims to make it easier to build and manage microservices. It provides a set of building blocks that developers can use to build distributed applications, without having to worry about the underlying infrastructure.
The main benefits of using Dapr is that it abstracts away the complexities of building and managing microservices. It provides a set of pre-built, modular components that developers can use to build their applications, such as Service Invocation, State Management, Pub/Sub Messaging, Input/Output binding, Secret Management, Virtual Actors and more.
This allows developers to focus on building and testing their core business logic, rather than worrying about the underlying infrastructure.
For example, Dapr’s service invocation component allows developers to easily invoke services using a simple HTTP-based REST API (or, alternatively, gRPC API), without having to worry about the details of how the service is implemented or where and how it is deployed.
Dapr is language-agnostic, meaning that it can be used with a variety of programming languages and frameworks. This makes it easier for teams to choose the tools that best fit their needs and skillset, rather than being tied to a specific technology stack. This is especially useful in environments where developers are using different languages and frameworks, as it allows them to easily integrate with one another and build cohesive distributed systems.
Dapr also provides built-in support for observability, which is crucial for understanding how an application is functioning in production. It integrates with popular observability tools, such as Prometheus and OpenTelemetry, to provide visibility into the performance and health of microservices, empowering developers to quickly identify and resolve issues, improving the overall reliability and performance of their applications.
Dapr is designed to be portable, meaning that it can run on any platform, including cloud, on-premises, and hybrid environments. This allows developers to build and deploy applications without being tied to a specific infrastructure provider, allowing companies that adopt this framework greater flexibility and control over the deployment infrastructure. This is especially useful in situations where an application needs to be deployed to multiple environments, such as in a hybrid cloud scenario.
Example Use Case – Payment Gateway
A payment gateway is a service that allows merchants to securely process credit cards and other forms of electronic payments. It typically sits between the merchant’s e-commerce platform and the payment processors (e.g Visa, Mastercard, Amex).
The architecture diagram for this use case could look like the one in this figure:
The Payment Gateway Service is responsible for handling the request from the merchant and securely forwarding the payment details to the Payment Processor. It could use Dapr’s state management component to store the payment status in a key-value store.
The Payment Processor Service is responsible for communicating with the Payment Networks ( Visa, Mastercard, etc ) to perform the actual transaction.
The Merchant Service is responsible for handling merchant information and could use Dapr’s state management component to store merchant data in a NoSQL database.
The services can communicate with each other using Dapr’s pub-sub messaging component. Communication examples:
- a merchant initiates a payment, the Payment Gateway Service will publish an event to the Payment Processor Service with the payment details.
- when the Payment Processor Service finishes the payment, it could publish an event to the Payment Gateway Service with the transaction details.
- the Payment Gateway Service could publish an event to the Merchant Service with the payment status.
Comparison with other tools, limitations
While Dapr shows very interesting capabilities, it’s worth noting that Dapr is still a relatively new technology, and as such, it may not have all the features and capabilities of more established solutions. Some users may find that Dapr lacks certain advanced features or integrations that they need for their specific use case.
Dapr may not be the best fit for all types of microservice architectures, for example, it may not be suitable for very large or complex systems.
In addition to these potential limitations, it’s worth considering how Dapr compares to other solutions that are available for building and managing microservices.
One popular alternative is Kubernetes, which is a container orchestration platform that is widely used for deploying and managing microservices. Kubernetes provides many of the same features as Dapr, such as service discovery, load balancing, and observability, and it is also portable and language-agnostic. However, it may be more complex to set up and manage than Dapr, and it may not be as lightweight or easy to use for certain types of applications.
Another alternative is service mesh technologies, such as Istio and Linkerd, which provide a layer of infrastructure for managing communication between microservices. Service meshes offer a number of features that are similar to those provided by Dapr, such as service discovery, load balancing, and observability, and they are also portable and language-agnostic. However, service meshes can be complex to set up and manage, and they may not be the best fit for all types of applications.
Conclusion
Ultimately, the choice between Dapr and other solutions will depend on the specific needs and goals of your project. Dapr may be a good fit if you are looking for a lightweight, easy-to-use solution that is well-suited to building and managing microservices, while Kubernetes or service meshes may be a better fit for larger or more complex systems.
It’s important to always carefully evaluate the options, and choose the solution that best meets your project and organisation needs.
References
About Claudiu Farcas
Claudiu is a software architect, and, in his own words, he helps companies design and build better software systems. With a strong understanding of both the technical and the business domains his project activates in, and over 15 years of experience in software development and project management, Claudiu is always eager to share his knowledge with both his colleagues and the clients on the projects he works on.