Author: ultroni1

  • Implement application resiliency

    The resiliency features of .NET are built upon the Polly project and made available through Microsoft.Extensions. You can add a standard resilience strategy that uses sensible defaults by adding a single line of code to your app.

    Add resilience to your app

    To add resilience to an app built using a microservices architecture, using HTTP requests between individual services, take these steps:

    1. Add the Microsoft.Extensions.Http.Resilience package to your project.
    2. Add a resilience handler to your HttpClient service calls.
    3. Configure the resilience strategy.

    Add the NuGet package to your project

    Run the following command to add the resiliency NuGet package:

    .NET CLICopy

    dotnet add package Microsoft.Extensions.Http.Resilience
    

    Running this command from the terminal in the apps project folder will add the package reference to the project file.

    Then add the following using statement in your application’s startup class :

    C#Copy

    using Microsoft.Extensions.Http.Resilience;
    

    Add a resilience strategy

    You can now add a standard resilience strategy to your HttpClient service. .NET provides this out-of-the-box configuration combining a number of strategies.

    A diagram showing the strategies included in the Standard Resilience Handler. From overall timeout, retry, bulkhead, circuit breaker, and attempt timeout.

    The request handler goes through each of these strategies in order form left to right:

    • Total request timeout strategy: This sets a total amount of time that the request can take. You can think of this as setting the upper time limit for all the other strategies.
    • Retry strategy: This strategy controls the options on number of retries, backoff, and jitter. These options can’t exceed the total timeout set in the previous strategy.
    • Circuit breaker strategy: This strategy opens the circuit if the failure ratio exceeds the threshold.
    • Attempt timeout strategy: This strategy sets a timeout for each individual request. If the request takes longer than this time, then an exception is thrown.

    You can add this standard strategy, with all the default values by adding this extension method:

    C#Copy

    .AddStandardResilienceHandler();
    

    For example if you have declared a WebApplication, and you want to add a resilience strategy to the HttpClient service use this code:

    C#Copy

    builder.Services.AddHttpClient<ServiceBeingCalled>(httpClient =>
    {
        httpClient.BaseAddress = new Uri("https://service.endpoint/");
    }).AddStandardResilienceHandler();
    

    The first line of the preceding code adds a standard resilience handler to the HTTPClient. This will use all the default settings for the retry and circuit breaker strategies.

    php programming training courses malaysia
  • Retry strategy

    Retry strategy is exactly what the name implies. The request is retried after a short wait if an error response is received. The wait time increases with each retry. The increase can be linear or exponential.

    After the maximum number of retries is reached, the strategy gives up and throws an exception. From the user’s perspective, the app usually takes longer to complete some operations. The app might also take some time before informing the user that it couldn’t complete the operation.

    Circuit Breaker strategy

    Circuit Breaker strategy gives a target service a break after a repeated number of failures by pausing trying to communicate with it. The service could be experiencing a serious problem and be temporarily unable to respond. After a defined number of consecutive failures, the connection attempts are paused, opening the circuit. During this wait, additional operations on the target service fail immediately without even trying to connect the service. After the wait time has elapsed, the operation is attempted again. If the service successfully responds, the circuit is closed and the system goes back to normal.

    Infrastructure-based resiliency

    To implement infrastructure-based resiliency, you can use a service mesh. Aside from resiliency without changing code, a service mesh provides traffic management, policy, security, strong identity, and observability. Your app is decoupled from these operational capabilities, which are moved to the infrastructure layer.

    Comparison to code-based approaches

    An infrastructure-based resiliency approach can use a metrics-based view that allows it to adapt dynamically to cluster conditions in real time. This approach adds another dimension to managing the cluster but doesn’t add any code.

    power bi training courses malaysia
  • Application and infrastructure resiliency

    Resiliency is the ability to recover from transient failures. The app’s recovery strategy restores normal function with minimal user impact. Failures can happen in cloud environments, and your app should respond in a way that minimizes downtime and data loss. In an ideal situation, your app handles failures gracefully without the user ever knowing there was a problem.

    Because microservice environments can be volatile, design your apps to expect and handle partial failures. A partial failure, for example, can include code exceptions, network outages, unresponsive server processes, or hardware failures. Even planned activities, such as moving containers to a different node within a Kubernetes cluster, can cause a transient failure.

    Resiliency approaches

    In designing resilient applications, you often have to choose between failing fast and graceful degradation. Failing fast means the application will immediately throw an error or exception when something goes wrong, rather than try to recover or work around the problem. This allows issues to be identified and fixed quickly. Graceful degradation means the application will try to keep operating in a limited capacity even when some component fails.

    In cloud-native applications, it’s important for services to handle failures gracefully rather than fail fast. Since microservices are decentralized and independently deployable, partial failures are expected. Failing fast would allow a failure in one service to quickly take down dependent services, which reduce overall system resiliency. Instead, microservices should be coded to anticipate and tolerate both internal and external service failures. This graceful degradation allows the overall system to continue operating even if some services are disrupted. Critical user-facing functions can be sustained, avoiding a complete outage. Graceful failure also allows disturbed services time to recover or self-heal before impacting the rest of the system. So for microservices-based applications, graceful degradation better aligns with resiliency best practices like fault isolation and rapid recovery. It prevents local incidents from cascading across the system.

    There are two fundamental approaches to support a graceful degradation with resiliency: application and infrastructure. Each approach has benefits and drawbacks. Both approaches can be appropriate depending on the situation. This module explains how to implement both code-based and infrastructure-based resiliency.

    Code-based resiliency

    To implement code-based resiliency, .NET has an extension library for resilience and transient failure handling, Microsoft.Extensions.Http.Resilience.

    It uses a fluent, easy-to-understand syntax to build failure-handling code in a thread-safe manner. There are several resilience policies that define failure-handling behavior. In this module, you apply the Retry and Circuit Breaker strategies to HTTP client operations.

    prince2 certification training courses malaysia
  • Microservices orchestration

    Contoso loves the results of using a microservices architecture so far. The overall web application calls individual microservices to provide and manipulate data.

    But as more services are added, the overall system becomes more complex to scale out and manage. Orchestrators can help.

    What is an orchestrator?

    An orchestrator is a tool that helps you manage, scale, and maintain a containerized application.

    Using orchestrators for production-ready applications is essential if your application is based on microservices or is split across multiple containers. As noted earlier, in a microservice-based approach, each microservice owns its model and data. The microservice is autonomous from a development and deployment point of view. These kinds of systems are complex to scale out and manage. Therefore, to have a production-ready and scalable multi-container application, you absolutely need an orchestrator.

    python programming training courses malaysia
  • What are microservices?

    The cloud drives today’s application development and IT systems management. Modern cloud applications need to be fast, agile, massively scalable, and reliable.

    Using containers can help you deploy applications that meet all of those requirements. But putting an application into a container without following a strategic design pattern is like getting into a vehicle and hoping to find your way to a new city without using a map or GPS. You might end up at your destination, but the route probably won’t be direct or the most efficient.

    A microservices architecture is useful in this scenario. Microservices give you an approach to software development and deployment that’s perfectly suited to the agility, scalability, and reliability requirements of modern cloud applications.

    What is a microservices architecture?

    In a microservices architecture, a large application is split up into a set of smaller services. Each service runs in its own process and communicates with other processes by using protocols like HTTP/HTTPS, WebSocket, or Advanced Message Queuing Protocol (AMQP). Each microservice implements a specific, end-to-end domain or business capability within a certain context boundary. Each microservice must be developed autonomously and must be independently deployable. Finally, each microservice should own its related domain data model and domain logic. Microservices can be based on different data storage technologies (SQL, NoSQL) and different programming languages.

    red hat certified architect rhca malaysia

  • Review app configuration concepts

    Creating microservices for a distributed environment presents a significant challenge. Cloud-hosted microservices often run in multiple containers in various regions. Implementing a solution that separates each service’s code from configuration eases the triaging of issues across all environments.

    In this unit, explore how to integrate ASP.NET Core and Docker configuration features with Azure App Configuration to tackle this challenge in an effective way.

    You’ll review the:

    • ASP.NET Core configuration infrastructure.
    • Kubernetes configuration abstraction—the ConfigMap.
    • Azure App Configuration service.
    • .NET Feature Management library.
    • Feature flag components implemented in the app.
    red hat certified engineer rhce malaysia

  • View telemetry with Azure Monitor and third-party tools

    Your app is collecting telemetry data, and you now need a more comprehensive way to view it. In this unit, you’ll see how to view telemetry data in many different tools.

    Monitor and view telemetry data

    A common way to view telemetry data is to use Prometheus and Grafana together. Prometheus is an open-source monitoring system that collects metrics from your cloud-native app. Grafana is an open-source visualization tool that you use to create dashboards to view the metrics collected by Prometheus.

    Prometheus

    The first step is to add a Prometheus container, and configure it to collect data from each microservice in your app. You then add the Prometheus .NET client library to collect metrics from the app.

    Screenshot that shows the configured Prometheus app showing the health of the eShopLite app.

    OpenTelemetry provides an exporter for Prometheus. You can add this exporter to your app by including the OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package. This package exports metrics to Prometheus in a format that it can understand. You replace the current console exporter with the Prometheus exporter.

    You add the endpoints for all the microservices in your app. For example:

    ymlCopy

    global:
      scrape_interval: 1s
    
    scrape_configs:
      - job_name: 'products'
        static_configs:
          - targets: ['backend:8080']
      - job_name: 'store'
        static_configs:
          - targets: ['frontend:8080']
    
    mysql database training courses malaysia

  • Add observability to a cloud-native application

    Now that you understand the importance of observability, you’ll see how you can include it in your cloud-native application. You do this step by adding OpenTelemetry to your app.

    Add OpenTelemetry to your app

    .NET has a rich ecosystem of built-in observability tools that produce logging, metrics, and tracing data. You can use these tools to add observability to your cloud-native application. These libraries are:

    • LoggingMicrosoft.Extensions.Logging.ILogger
    • MetricsSystem.Diagnostics.Metrics.Meter
    • TracingSystem.Diagnostics.Activity and System.Diagnostics.ActivitySource
    red hat certified specialist in deployment and systems management malaysia

  • What is observability?

    Before you dive into the code, let’s take a step back and talk about observability. You need to have tools that help you understand the internal state of a system based on what’s visible externally.

    Why implement observability?

    There are several reasons why observability is a crucial aspect of developing and improving cloud-native applications:

    • Understanding system behavior: Observability provides insights into how your application is performing and where bottlenecks or errors occur.
    • Debugging and troubleshooting: When issues arise, observability tools can provide detailed information about what was happening in the system at the time of the issue.
    • Continuous improvement: Observability isn’t just for identifying and resolving issues—it’s also used for continuous improvement. By monitoring system performance over time, you can identify opportunities to optimize your code, improve system performance, and quantitatively improve the experience to your users.
    • Proactive issue detection: With the right observability tools in place, you can often detect issues before your users even see them.

    Implementing observability in cloud-native applications isn’t just a best practice, it’s a necessity for maintaining, optimizing, and continuously improving your applications. It empowers developers to deliver reliable, high-performing applications and provides the insights needed to drive informed decision-making.

    The three pillars of observability

    There are three main pillars of observability:

    • Logs: Logs provide detailed records of events that occur within an application or system. In your app, you can use Microsoft.Extensions.Logging infrastructure to log events.
    • Metrics: Metrics refer to numerical measurements and counters that provide insight into a system’s performance and health. Examples include request rates, response times, CPU/memory usage, and error rates. In your app, you might have specific measurements that you need to track.
    • Distributed tracing: This process involves tracing a request as it propagates through all the microservices in your cloud-native app. Each service logs tracing data like request IDs that allow you to correlate events across services. Distributed tracing is also useful for debugging performance issues and errors in complex systems.

    Together, these three pillars provide comprehensive observability into a system.

    Sources of data for telemetry

    In your company’s cloud-native app, there are several sources of telemetry you could choose to collect:

    • Application logs: Applications generate logs that provide detailed information about its operation and errors if they occur. Logging is a rich source of telemetry data.
    • Databases: Databases can provide telemetry data about the queries they process, execution times, and any errors that occur.
    • HTTP requests and responses: The HTTP requests and responses between your microservices provide rich and valuable telemetry data. This data includes the request and response headers, body content, status codes, and timing information.
    • Client-side performance data: In cloud-native apps with a front end, you can collect the client-side performance data. This data might include page hits, load times, and UI interaction times.
    • Infrastructure metrics: If your application is hosted in a cloud environment, you can collect infrastructure metrics like CPU usage, memory usage, network traffic, and disk I/O operations.
    red hat certified specialist in red hat enterprise linux diagnostics and troubleshooting malaysia

  • Generate compliance reports for an annotated cloud-native app

    Compliance departments need to be able to review code and compliance reports to ensure that the application is compliant with the company’s policies. The .NET compliance framework provides a way to generate reports that show the compliance status of the application.

    What is a compliance report?

    A compliance report can be generated at compile time. The .NET compliance framework generates a JSON file that contains details on the data classifications and redaction methods used in the application.

    JSONCopy

    {
        "Name": "DataEntities",
        "Types": [
            {
                "Name": "DataEntities.Order",
                "Members": [
                    {
                        "Name": "CustomerAddress",
                        "Type": "string",
                        "File": "C:\\Developer\\mslearn-dotnet-cloudnative\\dotnet-compliance\\eShopLite\\DataEntities\\Order.cs",
                        "Line": "25",
                        "Classifications": [
                            {
                                "Name": "EUIIData"
                            }
                        ]
                    },
                    {
                        "Name": "CustomerName",
                        "Type": "string",
                        "File": "C:\\Developer\\mslearn-dotnet-cloudnative\\dotnet-compliance\\eShopLite\\DataEntities\\Order.cs",
                        "Line": "21",
                        "Classifications": [
                            {
                                "Name": "EUIIData"
                            }
                        ]
                    },
        ...
    

    The report above is an example from the eShopLite.DataEntities project. It shows that the Order class has two properties that are classified as EUIIData.

    JSONCopy

    {
        "Name": "Store",
        "Types": [
            {
                "Name": "Store.Services.Log",
                "Logging Methods": [
                    {
                        "Name": "LogOrders",
                        "Parameters": [
                            {
                                "Name": "logger",
                                "Type": "Microsoft.Extensions.Logging.ILogger",
                                "File": "C:\\Developer\\mslearn-dotnet-cloudnative\\dotnet-compliance\\eShopLite\\Store\\Services\\ProductService.cs",
                                "Line": "103"
                            },
                            {
                                "Name": "order",
                                "Type": "DataEntities.Order",
                                "File": "C:\\Developer\\mslearn-dotnet-cloudnative\\dotnet-compliance\\eShopLite\\Store\\Services\\ProductService.cs",
                                "Line": "103"
                            }
                        ]
                    }
                ]
            }
        ]
    }
    

    The report above is an example from the eShopLite.Store project. It shows that the LogOrders method in the ProductService class takes an Order object as a parameter for logging.

    red hat certified specialist in linux performance tuning malaysia