Sin categoría

Building Scalable Microservices with .NET 6: Leveraging the Power of Azure Cloud Services

This series of videos demonstrates the step-by-step process of creating and setting up all the essential Azure Services required for constructing a Microservice architecture within the Azure Cloud environment and .Net 6.

No alt text provided for this image

The next image demonstrates the architecture followed in the videos. It contains the list of Azure Cloud Services used to build the ecosystem for our microservices to interact with each other.

  1. Azure Resource Groups
  2. Azure Data Bases
  3. Microservices in .Net 6
  4. Azure Repos
  5. Azure AppConfig
  6. Azure Service Bus
  7. Azure Functions
  8. Azure Redis
  9. Azure Pipelines (CI)
  10. Azure Containers Registry
  11. Azure Pipelines (CD)
  12. Azure Kubernetes Cluster
  13. Azure API Management
  14. Azure Cost Management

0 Azure Resource Group

A resource group in Azure is a logical container for resources that are deployed in an Azure subscription. It allows you to manage and organize resources in a way that makes sense for your organization, such as grouping resources by project, application, or environment. You can use resource groups to manage access and apply policies to resources, and you can also use them to delete multiple resources at once.

1 Azure Databases

No alt text provided for this image

Azure offers various types of databases to cater to different data storage and management needs. Here are some of the popular database services provided by Azure:

  1. Azure Cosmos DB: A globally distributed, multi-model database service that supports NoSQL databases such as key-value, column-family, document, and graph databases.
  2. Azure SQL Database: A fully managed relational database service based on Microsoft SQL Server. It provides high availability, automatic backups, and scalability.
  3. Azure Database for MySQL: A fully managed MySQL database service that offers high availability, automatic backups, and built-in intelligence.
  4. Azure Database for PostgreSQL: A fully managed PostgreSQL database service that provides high availability, automatic backups, and built-in intelligence.
  5. Azure Database for MariaDB: A fully managed MariaDB database service that offers high availability, automatic backups, and built-in intelligence.
  6. Azure Synapse Analytics: A limitless analytics service that combines big data and data warehousing capabilities. It can handle both structured and unstructured data.
  7. Azure Cache for Redis: A fully managed, open-source, in-memory data store that can be used as a cache or a message broker.
  8. Azure Data Explorer: A fast and highly scalable data exploration service designed for analyzing large volumes of data in real-time.
  9. Azure Table Storage: A NoSQL key-value store suitable for storing large amounts of structured data.
  10. Azure Databricks: A fast, easy, and collaborative Apache Spark-based analytics platform that integrates with other Azure services for big data processing.

These are just a few examples of the types of databases offered by Azure. Depending on your specific requirements, there may be additional specialized database services available as well.

The first step following our diagram is to create the SQL Server and the 2 databases inside the server, 1 Posgress SQL Database and 1 CosmosDB NoSQL (it’s important to choose CosmosDB NoSQL with allows output binding on the Azure Function)

CONFIG_DATABASE_HISTORY:DB_TRANSACTION_HISTORY
CONTAINER_NAME:transactionsCollection

2-5 .- Microservices in .Net 6

The system is using 4 microservices developed using .Net 6 which brings several new features, improvements, and enhancements across different areas of application development.

.NET 6 is to provide a powerful and versatile framework for developing modern, high-performance applications across multiple platforms. It brings together the best features and capabilities of previous versions of .NET, improves performance, enhances developer productivity, and supports a wide range of application scenarios.

No alt text provided for this image

Here are some key highlights of .NET 6:

  1. Cross-platform Development: With .NET 6, you can build and deploy applications on various platforms, including desktop, web, mobile, cloud, and IoT devices.
  2. Performance Improvements: .NET 6 introduces several performance enhancements, including faster startup times, reduced memory footprint, and improved just-in-time (JIT) compilation. These improvements lead to better application performance and responsiveness.
  3. Web Development: .NET 6 includes significant updates for web development. It introduces a new web framework called ASP.NET Core MVC, which provides a unified programming model for building web applications. It also enhances performance, introduces new HTTP features, and improves the developer experience.
  4. Cloud-Native Applications: .NET 6 focuses on enabling cloud-native development. It includes enhanced support for containers, microservices, and serverless applications. It provides better integration with popular container orchestrators like Kubernetes and enables efficient development and deployment of cloud-native applications.

2.-Security

Service where the authorization for the users is made. It connects to a SQL Server database and if the credential exits it will generate a JWT.

<ItemGroup
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="5.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.16.0" />
</ItemGroup>>

3.- Account

Account is in charge to retrieve the account information.

  <ItemGroup
    <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.7.0" />
    <PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="5.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.2" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
  </ItemGroup>>

4.- Transactions

Service where the operations of deposits and withdrawals are created by the users.

  <ItemGroup>
    <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.7.0" />
    <PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="5.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.3" />
  </ItemGroup>

5.- History

Service to provide the history of the transactions by user.

  <ItemGroup
    <PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.2.0" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
    <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.34.0" />
    <PackageReference Include="MongoDB.Driver" Version="2.19.1" />
  </ItemGroup>>

6 Azure Repos

Azure Repos is a collection of services that provide scalable, distributed version control and source code management functionality. It is a part of Azure DevOps and is built on the Git and Team Foundation Version Control (TFVC) version control systems. It allows developers to work together on code, track changes, and maintain a history of revisions.

No alt text provided for this image

7.- Azure AppConfiguration

Azure App Configuration is a cloud-based configuration management service provided by Microsoft Azure. It helps you centralize and manage application settings and feature flags in a secure and scalable manner. Azure App Configuration allows you to store configuration data separate from your code, making it easier to modify and manage settings without redeploying your applications.

No alt text provided for this image

AppConfig Keys:

CONFIG_CN_TRANSACTION
CONFIG_CN_SECURITY
CONFIG_CN_ACCOUNT
CONFIG_CN_HISTORY
CONFIG_DATABASE_HISTORY:DB_TRANSACTION_HISTORY
CONFIG_DATABASE_TRANSACTION_COLLECTION:transactionsCollection
VERSION:1
CONFIG_CN_REDIS
CONFIG_CN_SERVICE_BUS
CONFIG_TOPIC_TRANSACTION_SERVICE_BUS:transaction-topic
CONFIG_SUBSCRIPTION_ACCOUNT_SERVICE_BUS:account-suscription
CONFIG_SUBSCRIPTION_HISTORY_SERVICE_BUS:history-suscription
jwtKey:mySuperSecretKey 

8.- Azure Service Bus

Azure Service Bus is a cloud messaging service provided by Microsoft Azure. It enables reliable communication and coordination between applications and services, even when they are running on different platforms, environments, or at different times. The purpose of Azure Service Bus is to facilitate asynchronous and decoupled communication between distributed systems.

No alt text provided for this image

Here are some key features and purposes of Azure Service Bus:

  1. Messaging: Azure Service Bus provides a messaging infrastructure that allows applications to send and receive messages using various communication patterns like queues and topics. It supports both one-to-one and publish-subscribe messaging models.
  2. Decoupling: Service Bus enables loose coupling between components by allowing them to communicate indirectly through messages. Applications can send messages to a queue or topic, and other applications or services can consume those messages at their own pace.
  3. Reliability and Durability: Service Bus ensures reliable message delivery by providing features such as message persistence, duplicate detection, and transactional support. It guarantees that messages are not lost and are delivered in the order they were sent.
  4. Scalability: Service Bus scales automatically to handle varying workloads and message volumes. It can handle high throughput and provides features like partitioning and session support to handle large-scale messaging scenarios.
  5. Message Routing and Filtering: Service Bus allows messages to be selectively consumed based on criteria using subscriptions and filters. This enables efficient message routing and reduces the need for additional application logic.
  6. Protocol Support: Service Bus supports multiple messaging protocols, including AMQP, MQTT, and HTTP. This makes it compatible with a wide range of programming languages and platforms.
  7. Hybrid Connectivity: Azure Service Bus supports hybrid connectivity scenarios, allowing on-premises applications to communicate with cloud-based applications securely.

Overall, Azure Service Bus acts as a reliable and scalable messaging backbone for distributed systems, enabling decoupled communication and integration between applications, services, and components.

Azure Service bus configurations:

Topic:  transaction-topic

	Subscriptions:

	-> account-suscription

	-> history-suscription

9.- Azure Functions

Azure Functions is a serverless computing service provided by Microsoft Azure. It allows you to run your code in the cloud without worrying about the underlying infrastructure. Azure Functions enables you to execute your code in a serverless manner, meaning you only pay for the actual execution time of your functions.

No alt text provided for this image

The purpose of Azure Functions is to provide a scalable and event-driven platform for building and running small pieces of code (functions) that perform specific tasks or respond to events. Here are some key features and purposes of Azure Functions:

  1. Event-driven Execution: Azure Functions can be triggered by various events, such as HTTP requests, timers, queues, database updates, and message brokers. This enables you to build workflows, integrations, and event-driven architectures easily.
  2. Scalability: Azure Functions automatically scales to accommodate workload demands. It can dynamically allocate resources as needed, ensuring that your functions can handle high volumes of requests without manual intervention.
  3. Serverless Architecture: With Azure Functions, you don’t have to manage servers or worry about infrastructure scaling. The platform takes care of provisioning, scaling, and managing the execution environment for your functions, allowing you to focus on writing the code.
  4. Pay-per-Use Billing: Azure Functions follows a consumption-based pricing model. You are billed only for the actual execution time and resources consumed by your functions. When there is no incoming traffic, you pay nothing.
  5. Broad Language Support: Azure Functions supports multiple programming languages, including C#, JavaScript, Java, Python, and PowerShell. You can write your functions using your preferred language and leverage the rich set of available bindings and triggers.
  6. Integration with Azure Services: Azure Functions seamlessly integrates with other Azure services, such as Azure Storage, Azure Event Grid, Azure Service Bus, and Azure Cosmos DB. This allows you to easily build complex workflows and event-driven applications.
  7. Development and Deployment Flexibility: Azure Functions provides various options for developing and deploying functions, including Visual Studio, Azure Portal, Azure CLI, Azure DevOps, and continuous integration/continuous deployment (CI/CD) pipelines.

Azure Functions enables developers to focus on writing code for specific tasks or event handlers without worrying about the underlying infrastructure. It provides a serverless execution environment that scales automatically, integrates with various services, and offers cost-effective billing based on actual usage.

The next snipped is an Azure Function that is triggered by a message coming from an Azure Service Bus and saves the information into a CosmosDB using binding connection.

[FunctionName("history_process_azf")
public async Task Run(
[ServiceBusTrigger("transaction-topic", "history-suscription", Connection = "SB_Connection")] string serviceBusMessage,
[CosmosDB(
databaseName: "DB_TRANSACTION_HISTORY",
containerName: "transactionsCollection",
Connection = "CosmosDBConnection")] IAsyncCollector<TransactionModel> documentsOut)
{
var transaction = JsonConvert.DeserializeObject<TransactionModel>(serviceBusMessage);
await documentsOut.AddAsync(transaction);
_logger.LogInformation($"C# ServiceBus topic trigger function processed message: {serviceBusMessage}");
}]



 <ItemGroup
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="4.3.0" />
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.14.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.CosmosDB" Version="4.3.0" />
</ItemGroup>>

10.- Azure Redis Database

Azure Redis Cache is a fully managed, in-memory data storage service provided by Microsoft Azure. It is based on the popular open-source Redis (Remote Dictionary Server) and offers a distributed caching solution in the cloud. Azure Redis Cache allows you to store and retrieve data in a fast, scalable, and highly available manner.

No alt text provided for this image

The purpose of Azure Redis Cache is to improve the performance and scalability of applications by caching frequently accessed data in memory. Here are some key features and purposes of Azure Redis Cache:

  1. In-Memory Data Store: Azure Redis Cache stores data in memory, which provides fast read and write operations. By keeping data in memory, applications can access the cached data more quickly compared to retrieving it from disk-based storage.
  2. Caching: Azure Redis Cache acts as a distributed cache, enabling you to store key-value pairs. Applications can cache data such as database query results, session data, computed values, and frequently accessed data to reduce the load on backend systems and improve response times.
  3. High Performance: Redis is known for its high-performance capabilities, such as low latency, high throughput, and efficient data structures. Azure Redis Cache leverages these features to provide fast data access and response times.
  4. Scalability: Azure Redis Cache offers automatic scaling capabilities. You can increase or decrease the cache size based on your application’s needs without experiencing downtime or making manual configuration changes.
  5. Pub/Sub Messaging: Azure Redis Cache supports the publish/subscribe messaging pattern. Applications can publish messages to channels, and other applications or services can subscribe to those channels to receive the messages in real-time. This enables building real-time communication and event-driven architectures.
  6. Data Persistence: Azure Redis Cache provides options for data persistence, allowing you to store the cache data to disk periodically. This helps in scenarios where cache data needs to be retained even in the event of cache restarts or failures.
  7. Integration with Azure Services: Azure Redis Cache integrates well with other Azure services, such as Azure Functions, Azure App Service, and Azure Logic Apps. This allows you to leverage caching capabilities in your applications and services seamlessly.
  8. Security and Monitoring: Azure Redis Cache provides security features like SSL encryption, access control, and virtual network integration. It also offers monitoring and diagnostics capabilities to track cache usage, performance, and troubleshooting.

11.- Azure Pipelines Continuous Integration and Azure Container Registry

Azure Pipelines is a cloud-based continuous integration and continuous delivery (CI/CD) platform provided by Microsoft Azure. It helps you automate the build, test, and deployment processes for your applications across different platforms and environments. Azure Pipelines enables you to create efficient and reliable pipelines to deliver software updates faster and with higher quality.

No alt text provided for this image

The purpose of Azure Pipelines is to streamline and automate the software development lifecycle, from source code management to production deployment. Here are some key features and purposes of Azure Pipelines

Continuous Integration (CI): Azure Pipelines enables you to set up CI workflows to automatically build and test your code whenever changes are pushed to a version control repository. This helps catch integration issues early and ensures that your codebase is always in a releasable state.

Azure Containers Registry:

Azure Container Registry (ACR) is a managed, private container registry service provided by Microsoft Azure. It allows you to store and manage your container images in a secure and scalable manner. ACR is designed to simplify container image management and facilitate the deployment of containerized applications.

The main purpose of Azure Container Registry is to provide a centralized location for storing and distributing container images. Here are some key features and purposes of Azure Container Registry:

  1. Private Container Registry: ACR allows you to create and manage private repositories for your container images. It ensures that only authorized users or services can access and pull images from the registry.
  2. Secure Image Storage: ACR provides secure image storage by allowing you to encrypt images at rest and in transit. It integrates with Azure Active Directory for authentication and role-based access control (RBAC), ensuring granular control over who can perform actions on the registry.
  3. Fast and Reliable Image Distribution: ACR leverages the global Azure infrastructure to distribute container images efficiently across regions. It provides fast and reliable image replication, ensuring that images are available close to the deployment targets.
  4. Integration with Container Services: ACR integrates seamlessly with Azure’s container services, such as Azure Kubernetes Service (AKS) and Azure Container Instances (ACI). This allows you to easily deploy your containerized applications using the images stored in the registry.
  5. Image Lifecycle Management: ACR supports image versioning and retention policies, enabling you to manage the lifecycle of your container images. You can control how long images are retained, automatically delete older versions, and implement image vulnerability scanning and security checks.
  6. Build and Deployment Integration: ACR integrates with Azure DevOps and other CI/CD platforms, allowing you to automate the build and deployment processes of your container images. You can set up continuous integration pipelines to build and push images to the registry whenever there are changes in your source code.
  7. Geo-replication and Availability: ACR provides options for geo-replication, allowing you to replicate your container images to different regions for increased availability and resilience. This ensures that your images are accessible even in the event of a regional outage.
  8. Monitoring and Logging: ACR offers monitoring and logging capabilities to track registry activity, image pull rates, and diagnostic information. This helps you gain insights into the usage and performance of your container registry.

12- Azure Pipelines Continues Delivery with Releases and Azure Kubernetes Cluster

No alt text provided for this image

Kubernetes

A Kubernetes cluster in Azure is a managed environment for running containerized applications using the Kubernetes orchestration platform. Azure Kubernetes Service (AKS) is the specific Azure service that provides a fully managed Kubernetes cluster.

Here are the key aspects and features of a Kubernetes cluster in Azure:

  1. Kubernetes Orchestration: Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. A Kubernetes cluster in Azure utilizes Kubernetes to schedule and manage containers across a group of nodes.
  2. Managed Service: Azure Kubernetes Service (AKS) is a managed service provided by Azure that simplifies the deployment and management of Kubernetes clusters. It abstracts away the underlying infrastructure and takes care of the operational aspects, such as cluster provisioning, scaling, and monitoring.
  3. Scalability and Availability: AKS allows you to scale your Kubernetes cluster horizontally by adding or removing worker nodes as needed. It also provides high availability by distributing the workload across multiple nodes and ensuring that the cluster remains operational even in the event of node failures.
  4. Integration with Azure Services: AKS integrates seamlessly with other Azure services, such as Azure Container Registry, Azure Monitor, Azure Active Directory, and Azure DevOps. This integration allows you to leverage additional services for container image storage, monitoring, authentication, and continuous integration/continuous deployment (CI/CD).
  5. Infrastructure Management: With AKS, you don’t have to worry about managing the underlying infrastructure for your Kubernetes cluster. Azure takes care of the cluster’s infrastructure, including the control plane, networking, and storage, allowing you to focus on deploying and managing your applications.
  6. Security and Compliance: AKS provides built-in security features, including role-based access control (RBAC) for fine-grained access management, Azure Active Directory integration for user authentication, and network policies to control inbound and outbound traffic between pods. It also helps you meet compliance requirements by providing audit logs and monitoring capabilities.
  7. Monitoring and Scaling: AKS integrates with Azure Monitor to provide monitoring and diagnostics for your Kubernetes cluster and applications. It allows you to collect metrics, view logs, set up alerts, and autoscale your application workloads based on defined metrics.
  8. DevOps Integration: AKS supports integration with Azure DevOps. This enables you to automate the build, test, and deployment processes of your applications running on the Kubernetes cluster.

Continuous Delivery (CD): Azure Pipelines supports CD workflows to automate the deployment of your applications to various environments, such as development, staging, and production. It provides release management capabilities, allowing you to define deployment stages, approval gates, and promote releases across environments.

13 Azure API Management

Azure API Management is a service provided by Microsoft Azure that offers a comprehensive platform for managing APIs (Application Programming Interfaces). It acts as an API gateway, providing a centralized point for creating, publishing, securing, and monitoring APIs.

No alt text provided for this image

Azure API Management enables organizations to expose their APIs to external developers, partners, and internal teams in a secure and controlled manner. It offers various features and functionalities to simplify API management, including:

  1. API Gateway: Azure API Management acts as a gateway between clients and backend services, allowing you to publish APIs with different protocols and transform them to match the backend service requirements.
  2. API Lifecycle Management: It provides tools for designing, building, versioning, and retiring APIs. You can create API definitions using popular formats like OpenAPI (formerly Swagger) or import existing APIs.
  3. Security and Authentication: API Management allows you to enforce authentication and authorization policies for your APIs. It supports various authentication mechanisms like API keys, OAuth 2.0, and Azure Active Directory (Azure AD) integration.
  4. Rate Limiting and Throttling: You can control the rate at which clients can access your APIs to prevent abuse or excessive usage. Azure API Management offers rate limiting and throttling policies to manage API consumption.
  5. Analytics and Monitoring: It provides detailed insights and analytics about API usage, performance, and errors. You can monitor API traffic, track usage patterns, and identify issues to optimize your APIs.
  6. Developer Portal: Azure API Management includes a customizable developer portal where you can showcase your APIs, provide documentation, and offer self-service capabilities for developers to discover and consume your APIs.
  7. Integration with Backend Services: It supports integrating with various backend services, including Azure services like Azure Functions, Azure Logic Apps, and Azure App Service, as well as external services hosted on-premises or in other cloud providers.

Azure API Management simplifies the process of managing and scaling APIs while providing essential security and governance features. It is widely used by organizations to expose and manage their APIs in a secure and scalable manner.

14 Expensive Report

I’ll showcase the Cost-Effective Report while operating Microsoft Azure Cloud Services when selecting the less expensive options for each service. These services were incrementally created between May 15 and May 25.

No alt text provided for this image
No alt text provided for this image

Leave a comment