Posts

APIs and Microservices

Image
 UNDERSTANDING WEB APIs What are web APIs? As a review, an application programming interface (API) specifies how software components and systems should interact with each other. Web APIs extend this interaction beyond a single application by using HTTP, the language of the web, as the network protocol. A web API doesn’t have to be RESTful. It doesn’t have to use SOAP. It doesn’t have to use JSON or XML or OAuth or be built in a specific programming language or framework. It doesn’t have to have pretty URLs. Web APIs may exhibit some, all, or none of these traits. The only requirement for a web API is that it allows one program or software component to interact with another in a repeatable way over HTTP. Diagram of a simple web-based application that retrieves data from a database via an API. Effective API programs help to break down these siloed systems by decomposing them into smaller areas of concern (sometimes referred to as “bounded contexts”). These areas offer a clear API tha...

Microservice to use Commands or Events ?

 In a distributed application, it is likely to use a combination of commands, events, and queries to implement business use cases. Hence, it is necessary to thoroughly thought through and identify all possible service to service communication based on the use cases to decide upon which messaging to construct to use. When to use commands Consider using Commands for applications or services with below use cases suits; End to end message delivery guarantee between message producer and consumer. A consumer must process a message exactly once, not more than once. A consumer expects to process messages in the order they were published. Producer of a command expects a response from the receiver to confirm the completion of a task; as a way of assuring the integrity of a system. Using a message queue to deliver commands between components will address the above features. As an added advantage, message queues offer competing consumer pattern based message consumption at the receiving end. T...

Checklist on following DDD

 The checklist that can determine whether we are following proper Domain Driven Development standards;  Each service will have independent domain entities.  Entities should be different for each service. There is no comparison, each entity works differently for different purposes.  One command to one aggregate root. One entrypoint for each command.  Are we reading more than what we supposed to read?  The event store should capture only necessary events into event store that should have some purpose. Unnecessary events might pile up the cloud space.  List out all the valid events with valid reasons and sent to stake holders to validate their existence in the system.  List of the domain validations and send to the stake holders for validating them.  Failure mode analysis to be performed.

The Twelve Factors Applied to Microservices

Image
 In current technology evaluation, software is commonly delivered as a service: called web apps, or software-as-a-service. The twelve-factor app is a methodology for building software-as-a-service apps One codebase tracked in revision control, many deploys In a microservices architecture, the correct approach is actually one codebase per service. Explicitly declare and isolate dependencies Regardless of what platform your application is running on, use the dependency manager included with your language or framework. In a containerized environment, do this in the Dockerfile. Store config in the environment Anything that varies between deployments can be considered configuration. As guidelines recommend, storing all configuration in the environment, rather than committing it to the repository. We recommend the following specific practices:  - Use non‑version controlled .env files for local development. Docker supports the loading of these files at runtime.  - Keep all .env ...

Contract Testing using Pact

Image
 What is contract testing? Contract testing is a methodology for ensuring that two separate systems (such as two microservices) are compatible and are able to communicate with one other. It captures the interactions that are exchanged between each service, storing them in a contract, which can then be used to verify that both parties adhere to it. Contract testing goes beyond schema testing, requiring both parties to come to a consensus on the allowed set of interactions and allowing for evolution over time. What sets this form of testing apart from other approaches that aim to achieve the same thing, is that each system is able to be tested independently from the other and that the contract is generated by the code itself, meaning the contract is always kept up to date with reality. The following diagram shows the key steps in contract testing: How Contract testing works? The consumer provides a contract which it is expecting from the provider and the contract tests passes only wh...

Temporal and Behavioral Coupling

 Coupling is "the degree to which each program module relies on each one of the other modules".  Low coupling is typically a sign of a well-design implementation supporting the general goals of high readability and maintainability. Different distributed systems design approaches like Distributed 3-layer, Command-oriented, Event-oriented and Emergency services - impact two specific types of coupling: Temporal and Behavioral. Temporal Coupling : The degree to which the sending and handling of a message are connected in time. If a sender is dependent on a receiver being available when a message is sent, we have high temporal coupling... Processes whose activities are strictly ordered or whose results carry forward, leaving subsequent activities unable to start until a response to a prior request has been received, are similarly temporally coupled. Behavioral Coupling : The degree to which parties share assumptions regarding behaviors, more specifically, to the implications of as...

DDoS Attack for Distributed Microservices

A Distributed Denial-of-Service (DDoS) attack is a malicious attempt to disrupt the normal traffic of a targeted server, service or network by overwhelming the target or its surrounding infrastructure with a flood of Internet traffic. DDoS attacks achieve effectiveness by utilizing multiple compromised computer systems as sources of attack traffic. Exploited machines can include computers and other networked resources such as IoT devices.  DDoS attacks are carried out with networks of Internet-connected machines. These networks consist of computers and other devices (such as IoT devices) which have been infected with malware, allowing them to be controlled remotely by an attacker. These individual devices are referred to as bots (or zombies), and a group of bots is called a botnet . Once a botnet has been established, the attacker is able to direct an attack by sending remote instructions to each bot. When a victim’s server or network is targeted by the botnet, each bot sends requ...

Singleton is anti-pattern

The article below describes the behavior of the Singleton design pattern as an anti-pattern, where it violates the basic principle of creating a single object. We all are very much aware of Singletons, one of the main Creational Design Patterns. It's a very widely and commonly used Design Pattern. Most of you are aware of the advantages and the problems solved by the pattern, but I am not going to deal with those features in this article. What most of us fail to understand is that in most of the cases, the Singleton is misused and acts as an anti-pattern. So let's try to look at the scenarios where the Singleton design pattern works as an anti-pattern. ·          Singletons are basically used as global variables. Using global variables is an enemy of encapsulation because it becomes difficult to define pre- and post-conditions for the client’s object interface. The working of the interface can be handled from within, and not from...

Unity of Work Repository Pattern

Repository Pattern separates the data access logic and maps it to the entities in the business logic. It works with the domain entities and performs data access logic. In the Repository pattern, the domain entities, the data access logic and the business logic talk to each other using interfaces. It hides the details of data access from the business logic. In other words, business logic can access the data object without having knowledge of the underlying data access architecture . For example, in the Repository pattern, business logic is not aware whether the application is using LINQ to SQL or ADO.NET Entity Model ORM. In the future, underlying data sources or architecture can be changed without affecting the business logic. There are various advantages of the Repository Pattern including: Business logic can be tested without need for an external source Database access logic can be tested separately No duplication of code Caching strategy for the datasource can be centraliz...

Significance of Elasticsearch

Everyone is talking about one of the latest technologies called 'Elasticsearch'. Then some of the questions comes to my mind; - What is it, is it a database - Basics of Elasticsearch - How it runs - What it does - How to use - What are the dependencies Below I will explain my understanding and is to refer for myself as needed :-) ES is a document-oriented database designed to store, retrieve, and manage document-oriented or semi-structured data. When you use Elasticsearch, you store data in JSON document form. Then, you query them for retrieval. It is schema-less, using some defaults to index the data unless you provide mapping as per your needs. Elasticsearch uses Lucene StandardAnalyzer for indexing for automatic type guessing and for high precision. Every feature of Elasticsearch is exposed as a REST API: Index API: Used to document the index. Get API: Used to retrieve the document. Search API: Used to submit your query and get a result. Put Mapping AP...

Understanding Saga Pattern

Image
Yesterday evening in a casual talk I was discussing some technologies, I came across a new Pattern to me called 'Saga Pattern". Then I went through in the night and thought of putting across my understandings for my reference. This pattern mainly supported for Microservice implementations. If you are about to implement Microservices that implements a transaction that spans multiple services, this Saga pattern help you to solve the problem you face. If you are building a Travel booking App using Microservices; In the above diagram, a high-level business action (‘Booking a trip’) involves making several low-level actions to distinct microservices. To handle client requests, we create a single-purpose edge service (a Backend for Frontend) that provides the logic of composing calls to all the downstream services. At its core, the Travel Orchestrater - Travel Agent Service exposes APIs by composing core functionality provided by different Microservices. We all know t...

ASP.NET Core with Kestrel Webserver

The 1st question comes to my mind when I hear about another new webserver like IIS for .NET applications. Why do we need this new webserver called 'Kestrel'? As we all know Asp.Net Core is primarily to make Asp.Net Core applications to run across multiple platforms (Windows/Unix/Linux/MAC OS). Even though we have IIS with rich in features but mostly used webserver for Windows OS only. Each webserver has a different configurations expected to startup and Kestrel will make Asp.Net Core applications have different Startup mechanisms. This is why Asp.Net Core applications use Kestrel webserver as an in-process server where the application will have same and consistent Startup (Main() and Startup.ConfigireServices() & Startup.Configure()) process even when offering cross platform support. Kestrel is an open source, cross platform, light weight and a default webserver used for Asp.Net Core applications. Asp.Net Core applications run Kestrel webserver as in-process server to ...

Conditionally refer use 32/64 bit compile/runtime

Image
if your project requires references that are 32-bit or 64-bit specific (i.e. COM-interop assemblies), and you have no interest in manually editing the .csproj file, then you'll have to create separate 32-bit and 64-bit projects. Note that the following solution is should work. If you are willing to manually edit the .csproj file, then you should be able to achieve the desired result with a single project. The .csproj file is just an MSBuild script, so for a full reference, look here. Once you open the .csproj file in an editor, locate the elements. You should be able to split these elements out in to 3 distinct item groups: references that aren't platform specific, x86-specific references, and x64-specific references. Now when you set your project/solution build configuration to target the x86 or x64 platform, it should include the proper references in each case. Of course, you'll need to play around with the elements. You could even setup dummy projects where ...

ADO.NET Connection Transaction

Image
Lets talk about, how in various scenarios we can use TransactionScope with various options for managing real life transactions using ADO.NET. One of the important aspect for any business application is Transaction management. Each and every large scale development framework provides a component for managing transactions. .NET Framework is a large development framework and it also provides its own transaction management component. From.NET Framework 2.0 onwards TransactionScope class is available in the System.Transactions assembly. This class provides a transactional framework with the help of which any .NET developer can write transactional code without having much knowledge. To resolve transactional issues like deadlocks, timeouts, etc., you must know each and every concept directly/indirectly related to a transaction. There is no alternative. So the concepts of a transaction and its related components need to be clear. In a database transaction we can say, a series of MDL ope...