Showing posts with label ESB. Show all posts
Showing posts with label ESB. Show all posts

Friday, 9 June 2023

App Insights for Power Platform - Part 1 - Series Overview

Overview: Microsoft have great capabilities for logging and monitoring.  In this series of posts I will be examining the various parts of logging that may be useful in building solutions that are well monitored, provide alerting, easy tracing, and identifies issues or potential issues as soon as possible.

I am looking at App Insights for Power Platform monitoring.  So this includes: 

  • Power Apps (Canvas, and model apps),
  • Power Automate,
  • APIM, 
  • Azure Functions, 
  • Azure Service Bus, and
  • App Insights.

I shall be setting up a demo environment and these are the logical components being covered.


All the components making up the solution shall log into Log Analytics (left-hand side of the diagram).

For Continuous Integration, my clients will be Postman monitor (it's awesome and so easy to use all those postman collections), DevOps is great and I'll use it to run smoke tests after new releases.  I also use flows, to report on flows (sounds nuts but i love it).  These are at the bottom of the diagram. 

Lastly on the right of the diagram, I look at extracting logs for reporting (Power BI), and Monitoring using Azure DevOps (p.s. think about Grafana instead of DevOps Dashboards, it so nice).

Couple of extras are: Availability Logging, alerting, automating Canvas app testing, Playwright.  

From the diagram, you can see the data is now held in Log analytics and it can be queried via Log Analytics or App Insights using Kusto.  Note: the syntax is slightly different.

Series

App Insights for Power Platform - Part 1 - Series Overview (this post)

App Insights for Power Platform - Part 2 - App Insights and Azure Log Analytics 

App Insights for Power Platform - Part 3 - Canvas App Logging (Instrumentation key)

App Insights for Power Platform - Part 4 - Model App Logging

App Insights for Power Platform - Part 5 - Logging for APIM (this post)

App Insights for Power Platform - Part 6 - Power Automate Logging

App Insights for Power Platform - Part 7 - Monitoring Azure Dashboards 

App Insights for Power Platform - Part 8 - Verify logging is going to the correct Log analytics

App Insights for Power Platform - Part 9 - Power automate licencing

App Insights for Power Platform - Part 10 - Custom Connector enable logging

App Insights for Power Platform - Part 11 - Custom Connector Behaviour from Canvas Apps Concern

Tip: The Power Platform Admin Centre has a good overview of the Power Platform, but to make logging and monitoring better push data into Azure Log analytics and monitor and alert centrally.

Also seeView and download Dataverse analytics - Power Platform | Microsoft Learn

Saturday, 8 May 2021

Enterprise Service Bus and Message Queue thoughts

Message Queues have been around for many years and I've implemented message queue using: SonicMQ, MSMQ,  IBM MQ.  I like to keep my architecture as simple as possible so I still use queues but deciding between your "eventing" architecture brings Enterprise Service Buses (ESB) into picture and all the other players.  The last 2 native PaaS players for messaging are Event Grid and Event Hub (IoT).  It come down to what you are trying to achieve, are you going to need more functionality later, what does you business have available and the skills you have to work with.

I like Azure Storage Queues, they are cheap, simple to setup and understand so for simple message queue capability:

Azure Storage Queues sit on Azure Storage (Type Queue Storage).  Multiple queues can be on a single Queue Storage Account, and must be named in lowercase.  Messages up to 64kb.  Order of queued messages is not guaranteed.  Max message lifespan is use to be 7 days (default is 7 days), now maximum time-to-live can be set to -1 meaning never expire.  SAS token to pragmatically access.  REST API to add and pull from the Queue (also has a peek API).v  Azure Storage supports "Poison queue" so when the "Dequeued count" exceeps the threshold set on the queue, the message is moved into the "Poisoned Queue".  Pricing is pretty cheap and LRS is the cheapest with GA-GRS (Geo Redundant storage) being the most expensive.  

Get a message from the queue and amend the message to wait 60 seconds (Code Source: Microsoft Docs)
QueueClient queueClient = new QueueClient(connectionString, queueName);
// Get the message from the queue QueueMessage[] message = queueClient.ReceiveMessages(); // Update the message contents queueClient.UpdateMessage(message[0].MessageId, message[0].PopReceipt, "Updated contents", TimeSpan.FromSeconds(60.0) // Make it invisible for another 60 seconds

// DeQueue/Delete the message queueClient.DeleteMessage(retrievedMessage[0].MessageId, retrievedMessage[0].PopReceipt);

Azure Enterprise Service Bus (ESB), is a fully managed ESB service.  Allows for standard queues (point-to-point) or topics also called pub-sub (point-to-multipoint) messaging.  Has two external connectivity options use Hybrid connections (webSockets) over Azure Relay.  Messages up to 256kb except Premium up to 1MB message size allowed in queues, In topics, I think, the max message size allow is 100MB.  Unlimited lifespan.  Dead lettering option.  Programmatic access via SAS token, AAD.  Supports access via REST or AMQP (used for many years as the standard for Message Queues).  Has Duplicate message detection (ensures "At-most-once" delivery).



Standard has limitations such as messaging size, lower through put, no networking (firewall/NSG is useful for limiting IP's).
Source: https://www.serverlessnotes.com/docs/service-bus-namespace-standard-or-premium-tier 

AMQP can run on TCP on ports 5671 and 5672 or on https on port 443

Competitor options for Azure Enterprise Service Bus including message exchanging technologies: AWS SQS, GCP Pub Sub, NATs, Oracle ESB, JBoss Fuse, Mule ESB (from Mulesoft), IBM Websphere ESB, BizTalk, Azure EventGrid, Azure Storage Bus, Sonic ESB and I guess all the message ques link SonicMQ, IBM MQ.

Update 31 Jan 2022:  
Problem:  Messages are pushed onto the topic but are taking between 5 and 35 minutes to process.  The listener was an app registered on Service Fabric, and this started happening after we rebuilt a new instance of Service Fabric.  The Service Bus still work but 1 subscriber was taking this extra 5-35 minutes from what was previously being processed within 1 second.
Resolution:  As always, reboot :)  I disable the topic and re-enabled it and the messages were being processed within 1 second.  I could not find this behavior on google searches and after a lo fair amount of trying to check messages and configuration, a good old restart fixed the delay in message processing.

More Info:
NATS - Common ESB software gaining popularity



Sunday, 3 May 2020

Common Software Architectural Patterns

The goal of Solution Architecture is to:
To achieve a common understanding of how a technical solution will be reached, diagrams are useful. They also ensure a communicable roadmap and its completion. Later, the diagrams are used to ensure all relevant parties have a clear, unambiguous, shared understanding of the IT solution.

The main tools for communicating the architectural solution design are diagrams and documents that utilise common previously used and understood patterns to ensure a safe, scalable, stable, performant, and maintainable solution.  "4+1 view, which includes the scenario, logical, physical, process, and development views of the architecture", source.

Below are patterns and thoughts that I have come across and used to solve building high-quality solutions.

3/N Tier Architecture/Layered:
1) Presentation/UI layer
2) Business Logic
3) Data Layer/Data source
Here are a couple of possible examples over the years that you could have used
ASP > C++ Com > SQL Server 2000
ASP.NET (Web Forms) > C# Web Service (XML/SOAP) > SQL Server 2008
ASP.NET C# > C# Business Object Layer > SQL Server 2008
KO > MVC > SQL 2012
Angular 3 > C# Web API (swagger contract) > SQL 2016
REACT.JS > Node.JS > Amazon Redshift
UI > Azure Functions/Serverless > SQL Azure
Flutter > C# Web API .NET Core 3 (swagger/OpenAPI) published on Azure App Service > SQL Azure/Cosmos

API's:  Over the years, I have seen many different API's at a high level:  
  • Proprietary formatted API's > 
  • XML with SOAP coming out of XML based API's > 
  • REST/JSON (other popular formats are: RAML, GraphQL > 
  • Event-Driven APIs may be the next big jump.

Thoughts:  As time has progressed, scaling each of these layers has become easier.  For instance, Azure SQL has replication and high availability, and scalability automatically built in.  No need to think about load balancing in depth.  Plug and play and ask for more if you need it.
Microsoft SQL Server used to be a single server, then came replication, clustering, Always-on-availability, scaling greatly improved performance.
Middle Tier or Business layer use to be a singleton pattern - go thru a single server for business logic, slowly load balancing improved and caching become better.  Nowadays merely ramp on on you cloud provider.

Sharded Architecture: An Application is broken into many distinct units/shards.  Each shard lives in total isolation from the other shards.  Think SOA or Microservice architectures often use this approach.  "SOA is focused on application service reusability while Microservices are more focused on decoupling".  
Source: https://kkimsangheon.github.io

The problem with tight coupling multiple services are:
  1. Complexity - It is difficult to change code and know the effects.  Also, services need to be deployed together to test changes.
  2. Resilience - Service goes down, the whole suite goes down.
  3. Scalability - This can be an issue as the slowest component becomes the bottleneck.  
For instance, build a complete application to handle ordering and a separate system that handles inventory.  So both could be in different data stores, so let's say orders are on CosmosDB and Inventory is on Azure SQL.  Some of the inventory data is static in nature, so I decided to use App Caching (Redis).  Both data sources are based on independent server-less infrastructure.  So, if you see inventory has an issue, merely scale it.  The front-end store would seamlessly connect to both separately.  "Sharding" databases/horizontal partitioning is a similar concept, but only at the database level.  Sharding can be highly scaleable, allow for leveraging and reusing existing services, and can be flexible as it grows.  Watch out for 2 Phase Commit (2PC/Sagas/Distribute transactions)

Thoughts Pros: 
  1. Developers & Teams can work independently
  2. Great to reuse existing services instead of creating them yourself. e.g. App Insights on Azure.
  3. Great for high availability and targeted scalability.
  4. Zero trust security.  Explicitly Verify, Least privilege access.  Assume breach.  Impelment Defense in depth. Monitor & Analyse for threat protection.
  5. Focused costs by scaling the individual microservices.
Cons:
  1. Services need to be independent, or deployment becomes a challenge.
  2. Increased latency - you may need to go to various systems sequentially.
  3. Need keys to manage, e.g., clientId for this decouple architecture type. This architecture can also become complex, especially if you need to expand a shard to do something it doesn't do today.
  4. Data aggregation and ETL can become complex and have time delays.
  5. Referential integrity, guaranteed commit is an issue, we can use SAGA or 2PC to improve but not ACID.
  6. Rules for strict governance and communication between teams are needed.
  7. Monitoring and troubleshooting can be challenging.  Build a traceable service (App insights for finding and understanding issues, needs to be pollyfilled for long running operations, SPA's need unique correlationIds)
Event-driven architecture: The client sends a request that includes a response for the server to contact when the event happens.  So if asking a server to do a complex calculation, the client could keep polling a long-running operation until the server has the answer or use an Event-drive architecture. To Can you pls calculate, and when you are done, send the response to me at...  Types of Event-driven architectures are: WebHooks, WekSockets, ESB (pub-sub), Server Sent Events (SSE).
They are loosely coupled and only run when an event happens. In Azure, they generally cover Functions, Logic Apps, Event Grid (event broker), and APIM. They are easy to connect using Power Platform Connectors.
  • Client/Service sends a broadcast event.
  • Consumers listen for events to see if they want to use the event.
Hexagonal Architecture - Related/founder to Microservices,
Command Query Responsibility Segregation (CQRS) - pattern/method for querying and inserting data are different./seperated.  This is a performance and scaling pattern.
Domain-Driven Design (DDD) - Design software in line with business requirements.  The structure and language of the code must match the business domain.  DDD Diagrams help create a shared understanding of the problem space/domain to aid with conversation and further learning within the team.   "Bounded Context is a central pattern in Domain-Driven Design. It is the focus of DDD's strategic design section, which deals with large models and teams. DDD deals with large models by dividing them into different Bounded Contexts and being explicit about their interrelationships."  Martin Fowler.
RACI Diagram - a visual diagram showing the functional role of each person on a team or service.  Useful for seeing who is responsible for what part of a service or their role within a team.
Event Sourcing Pattern - Used for event-based architecture
AMQP is a standard used to pass business messages between systems.  AMQP is the default protocol used in Azure Service Bus.  AmazonMQ and RabbitMQ also support AMQP and are the main standards for the messaging protocol for event messaging.
Competing Consumer Pattern – Multiple consumers are ready to process messages off the queue.
Priority Queue pattern -Messages have a priority and are ordered for processing based on priority.
Queue-based load leveling.
Saga design pattern is a way to manage data consistency across microservices in distributed transaction scenarios.  Similar use case to 2PC but different. 
2PC (Two-phase Commit): A simple pattern to ensure multiple distributed web services are all updated or no transaction is done across the distributed services.  
Throttling pattern
Retry pattern - useful for ensuring transient failures are corrected,
The Twelve-Factor App methodology is a methodology for building software-as-a-service (SaaS) applications.

Key Design Decision (KDD) Document helps outline why decisions where made.  This is also often called Architectural Decisions Document or Template.
RAID Log - 

Streaming/MessageBus: Kafka, IoT,
Azure Messaging Service is made up of 6 products:
1. Service Bus—Normal ESB. Messages are put into the queue, and one or more apps can directly connect to or subscribe to topics.
2. Relay Service—This is Useful for SOA when you have infra on-prem. It exposes cloud-based endpoints to your on-prem Data sources.
3. Event Grid - HTTP event routing for real-time notifications.
4. Event Hub - IoT ingestion, highly scalable.
5. Storage Queues - point-to-point messaging, very cheap and simple, but very little functionality.
6. Notification Hub - 

Azure Durable Functions - Azure Functions are easy to create logic but are not good at long-running or varying length duration functions.  To get around the timeout limits, there are a couple of patterns for Functions, making them better at handling long-running operations.  The most common patterns are: Asyn HTTP APIs (Trigger a a function using HTTP, set off other functions and the client waits for an answer by polling a separate function for the result), Function Chaining (Execute functions sequentially once the last function completes), and Fan-out/Fan-in (first function call multiple functions that run in parallel) 

Lambda: great for large data architectures.  Has a batch vs streaming concept.  Each transaction pushed into a queue/stream (Kafka/Azure Queues/Azure Event Grid) and large data can be stored for later batch processing.

"Onion Architecture is based on the inversion of control principle. Onion Architecture is comprised of multiple concentric layers interfacing with each other towards the core representing the domain. The architecture does not depend on the data layer as in classic multi-tier architectures but on the actual domain models." Codeguru.com

Distributed Application Runtime, DaprVideo - Event drive portable runtime for building distributed applications on the cloud.  Open source project tries to support any language/framework, consistent portable APIs, and extensible components that are platform agnostic.  HTTP API.    Secure Service to service calls, state management, publish and subscribe (For Azure ESB, Azure Queue), resource binding (Azure Functions), observability (Azure Signal-R service), Secret stores (Azure Key Vault) components to provide specific functionality.  Building blocks are made up of components.  

Cell Architecture: a collection of components that are connectable and observable.  Cell Gateway is basically the service exposed.  Similar to APIM/API Gateway.  1 or more cell components make up Cell Gateway for ingress data.  Egress is done using Sidecar (App Insights is a great example of a sidecar service pattern). It is basically API first architecture.

SAST/DAST: are application security testing methodologies used to find application vulnerabilities.  Another threat modeling approach is STRIDE.

DACI (Decision Making Framework): stands for "driver, approver, contributor, informed", used to make effective and efficient group/team decisions.

OpenAPI vs GraphQL
OpenAPI specification (previously known as the Swagger specification) is my default for an API, this allows for a known RESTful API that anyone with access can use.   Open API has set contracts that returned defined objects which is great, you can work with the API like a database with simple CRUD operations as defined by the specification.  The issue is that the returned objects are fixed in structure so you may need 2 or more queries to get the data you are looking for.  Alternatively, GraphQL allows the developer to ask for the data exactly as the want it.
Open API example:
/api/user/{2} returns the user object  // Get the user object for user 2
/api/users/{2}/orders/10  // Returns the last 10 orders for the user
GraphQL example:
Post a single HTTP request.
query {
 User(id: "") {
    name
    email
    orders(last: 10 {
      orderid
      totalamount
      datemodified
    }
 }
You can see that GraphQL is potentially a better choice for complex changing systems. I also like the idea of using HASURA for ORM against PostgreSQL (hopefully SQL Server and others).

More Info: