What is an event bus in Android

Mapping eShopOnContainers to Azure services

  • 2 minutes to read

Azure is not required, but works well for eshoponcontainers support because the project was built as a native cloud application. The application is built with .NET so it can run on Linux or Windows containers depending on the docker host. The application consists of several autonomous, each of its own data. The different microservices illustrate different approaches, from simple CRUD operations to more complex DDD and cqrs patterns. The communication between the clients and clients via HTTP and message-based communication. The application also supports multiple platforms for clients as it adopts HTTP as the standard communication protocol and includes ASP.NET Core and Xamarin apps that run on Android, iOS, and Windows platforms.

The architecture of the application is shown in Figure 2-5. On the left are the client apps in mobile, traditional web and single-page application (spa) variants. On the right are the server-side components that make up the system, each of which can be hosted in docker containers and Kubernetes clusters. The traditional web app is based on the ASP.NET Core MVC application, which is displayed in yellow. This APP and the mobile and web spa applications communicate with the individual web services through one or more API gateways. The API gateways follow the BFF (Back-Ends for Front-End) pattern, which means that each gateway should support a specific front-end client. The individual microservices are listed to the right of the API gateways and contain both business logic and some kind of retention memory. SQL Server databases, redis cache instances and MongoDB / cosmosdb storage are used in the various services. On the far right is the system's event bus, which is used for communication between the services.

Figure 2-5. The eshoponcontainers architecture.

The server-side components of this architecture are easily mapped to the Azure services.

Container orchestration and clustering

The application's container-hosted services, from ASP.NET Core MVC apps to individual catalog and ordering and ordering, can be hosted and managed in Azure Kubernetes Service (AKS). The application can run locally on docker and Kubernetes, and the same containers can then be deployed to staging and production environments hosted in AKS. This process can be automated as explained in the next section.

AKS provides management services for individual clusters of containers. The application provides separate containers for each microservice in the AKS cluster, as shown in the architecture diagram above. This approach enables each individual service to scale regardless of its resource requirements. Each service can also be provided independently and, ideally, there should be no system downtime with such deployments.

API gateway

The eshoponcontainers application has several front-end clients and several different back-end services. There is no one-to-one correspondence between the client applications and the services they support. In such a scenario, writing client software to securely connect the various back-end services can be much more complex. Each client has to deal with this complexity on its own, which leads to duplication and many places where updates are made when changing services or implementing new policies.

Azure API Management (APIM) helps organizations publish APIs in a consistent and manageable manner. APIM consists of three components: the API gateway and the management portal (the Azure portal) and a developer portal.

The API gateway accepts API calls and routes them to the appropriate back-end API. It can also provide additional services like verification of API keys or JWT tokens and API transformation without code changes (e.g. to support clients expecting an older interface).

In the Azure portal you define the API schema and package various APIs in products. You can also configure user access, view reports, and configure policies for quotas or transformations.

The developer portal serves as the main resource for developers. It provides developers with API documentation, an interactive test console, and reports on your own usage. Developers can also use the portal to create and manage their own accounts, including support for subscriptions and API keys.

Using APIM, applications can expose different groups of services, each providing a back-end to a specific front-end client. APIM is recommended for complex scenarios. The simple API gateway Ocelot can be used for simpler requirements. The eshoponcontainers app uses Ocelot for its simplicity and because it can be deployed in the same application environment as the application itself. Learn more about eshoponcontainers, APIM and Ocelot.

Another option, if your application uses AKS, is to provide the input controller of the Azure gateway as a pod within your AKS cluster. With this approach, your cluster can be integrated with an Azure application gateway so that the gateway can load balance the traffic on the AKS pods. Learn more about the input controller of the Azure gateway for AKS.

Data

The different back-end services used by eshoponcontainers have different storage requirements. Several web services use SQL Server databases. The shopping cart microservice uses a redis cache for its persistence. The location microservice expects a MongoDB API for its data. Azure supports each of these data formats.

To support SQL Server databases, Azure has products for everything from single databases to highly scalable pools for elastic SQL databases. Single microservices can be configured to quickly and easily communicate with their own SQL Server databases. These databases can be scaled as needed to support each separate microservice.

The eshoponcontainers application stores the user's current shopping cart between requests. This aspect is managed by the shopping cart microservice, which stores the data in a redis cache. In development, this cache can be provided in a container, while it can be used in the production environment for redis. Azure Cache for redis is a fully managed service that offers high performance and reliability without the need for you to provision and manage redis instances or containers yourself.

The location for the location uses a MongoDB nosql database for its persistence. During development, the database can be provided in its own container, while the service in the production environment can use Azure Cosmos DB-API for MongoDB. One of the advantages of Azure Cosmos DB is the ability to use several different communication protocols including a SQL API and popular nosql APIs including MongoDB, Cassandra, Gremlin and Azure Table Storage. Azure Cosmos DB provides a fully managed and globally distributed Database as a Service that can be scaled to meet the needs of the services you use.

Distributed data in cloud-native applications is covered in more detail in Chapter 5.

Event bus

The application uses events to communicate changes between different services. This feature can be implemented with different implementations and the eshoponcontainers application uses rabbitmq. When hosting in Azure, the application uses Azure Service Bus for messaging. Azure Service Bus is a fully managed integration message broker that enables applications and services to communicate with each other in a decoupled, reliable, asynchronous manner. Azure Service Bus supports single queues as well as separate ones subjects in support of publisher and subscriber scenarios. The eshoponcontainers application uses topics with Azure Service Bus to support the distribution of messages from one microservice to any other service needed to respond to a specific message.

Resilience

Once deployed to production, the eshoponcontainers application can leverage multiple Azure services to improve resilience. The application publishes health checks that can be built into Application Insights to provide reports and alerts based on the availability of the app. Azure resources also provide diagnostic logs that can be used to identify and troubleshoot errors and performance issues. Resource logs provide detailed information on when and how different Azure resources are being used by the application. Learn more about cloud-based resilience features in Chapter 6.