infuerno.github.io

Pluralsight: Microsoft Azure for .NET Developers - Cloud Patterns and Architecture

Architecture in the Cloud

Patterns for building scalable cloud solutions

An Overview of Azure Services

IaaS

PaaS

Security and Management

Basic API Design

Adding Authentication

Sophisticated Web System

Adding Resilience and Availability

Managing APIs

Backend Architecture for Native Apps

DevOps with Containers and Kubernetes

Building for the IOT

IaaS

Cloud Patterns for Resilency

Resilient applications have two important characteristics:

One often influences the other. Resiliency is a trade off with cost and is therefore a business decision. Additional costs for resources, but also additional complexity which implicitily equals higher costs.

Redundant Storage

Availiability Sets for VMs

Replication and Point in Time Restores

App Services

SLAs

Microsoft publish the SLAs for Azure services: https://azure.microsoft.com/en-gb/support/legal/sla/. Need to recognise the conditions under which different SLAs are given e.g. VMs deployed in an Availability Set will have a different SLA to single instance VMs.

Connection Resiliency

services.AddDbContext<ApplicationContext>(options =>
{
    options.UseSqlServer(Configuration.GetConnectionString("default"))
    sqlOptions => sqlOptions.EnableRetryOnFailure());
});

Graceful Degradation

When retry still isn’t working. Need to provide the best experience when things have gone wrong in one part.

The added complexity with add cost, but for example can add a ready only Redis Cache to have all data the main database has to at least service reads. CQRS and event sourcing pattern comes in handy here to give a structure and make resilient systems easier to implement.

Load Balancing

Azure Traffic Manager

A “profile” can be set to one of several Routing Methods:

Azure Traffic Manager Endpoints

Load Levelling

Azure Service Bus

Metrics shown on summary:

Testing

Important to simulate sceanrios for the resilience that is in place to ensure it works.

Monitoring

Despite the in built diagnostics - need to add logging and instrumentation. Have alerts set up - be on the look out for unusual behaviour. Web logs, database logs, OS performance counters

Cloud Patterns for Scalability

Performance is usually thought of as the speed with which ONE request can be actioned.

Scalability, on the other hand, is how well an application copes with 1000s of requests.

A Sample Architecture

The Importance of Partitioning

Data storage is often a bottleneck.

Will complicate the design and will be difficult to join data or transactions across the partitions, but needed to be able to scale this aspect.

Azure SQL Sharding

Each database has the same schema, but with different records inside. Can shard on a range (as above) or a tenant id if hosting for different tenants. One extra database is the “shard map manager” which contains all the metadata about how to reach all the metadata in the shard set of databases.

The database for each tenant can furthermore be scaled vertically (increase the capacity for a busy tenant etc).

Databases can also be placed into an elastic pool. Azure provides “elastic” tools to manage and work with shard sets. E.g. Elastic database job allows executing SQL commands against all the databases in the shard set, elastic query for querying for all data.

Most database technologies in Azure have a partitioning strategy e.g. CosmosDB

Understanding the CAP Theorum

Useful in thinking about designing the qualities of distributed systems.

Put forward by Eric Brewer who stated that a distributed system can only have 2 of the 3 guarantees. Therefore need to find which 2 qualities are most important.

The choices will depend on the business. Also, some parts of the system can be different.

Common Application Patterns

Configuring and Using Redis Cache

The StackExchange.Redis nuget package (included in the meta package Microsoft.AspNetCore.App) contains a client for interacting with a redis cache. This can be done via specifically interacting to redis OR via IDistributedCache

// establish connection
var connectionString = "amarula-redis.redis.cache.win ... Connect=False";
var connection = ConnectionMultiplexer.Connect(connectionString);
_redis = connection.GetDatabase();

// get a STRING
var greeting = _redis.StringGet("greeting");

// set a STRING
_redis.StringSet("greeting", greeting);

public CacheController(IDistributedCache cache)
{
    _cache = cache;

    // get a STRING
    var greeting = _cache_.GetString("greeting");

    // set a STRING
    _redis.SetString("greeting", greeting);    
}

// in Startup.ConfigureServices
public void ConfigureServices(IServiceCollection services)
{
    services.AddDistributedRedisCache(options => {
        options.Configuration = "amarula-redis.redis.cache.win ... Connection=False";
    })
}

The Role of CDNs

Azure CDN has support for SSL and custom domains. Can cache content from web app, blob storage or any web location.

  1. Set up a CDN profile which allows working with one or more endpoints (which can be set up to ANY web content).
  2. Set up an endpoint for e.g. amarula-traffic - Azure Traffic Manager. When the CDN is initially queried it won’t have the asset and will query it from the associated endpoint. Thereafter it will be cached. (Current the web app option doesn’t work well with traffic manager so choose custom)

Azure API Gateway

Cloud Patterns for Testing

Requirements

Simple URL Testing

Can set up a simple load test on an Azure App service iteslf. App Service > Performance Test.

Visual Studio Enterprise has tooling to perform more sophisticated tests including HTTP POSTs and paramteters.

Prepare a web application for testing

Creating a Web Test