APIs are an interface to external world for the services offered by organization. They interwork with each other to deliver complex functionalities. It uses simpler protocols and provides more sophistication around the exposure itself, including developer portals, policy controls, and self-administration.
In current context, APIs are tightly coupled with the business logic, which could be reusable component. This causes, difficulty in making quick changes in the APIs and business logic, as the whole sub-system has to go through the elaborate release processes for complete system. Also, fault in one of the pieces of complex business logic can lead to the failure of complete service. Such tightly coupled systems are known as monolithic designs.
Modern day Internet organizations have solved this problem by taking away business logic from APIs and converting them into microservices, which evolve independently, while providing reusable functionality to all the systems, very small code base, easy to deploy,change and support. These are available as plug-and-play components to create new APIs at API gateways.
API Gateway is a fully managed service that makes it easy for developers to create, publish, maintain, monitor, and secure APIs at any scale. With a few clicks in the Management Console, you can create an API that acts as a “front door” for applications to access data, business logic, or functionality from your back-end services, such as workloads running on cloud or any Web application. The API Gateway handles all the tasks involved in accepting and processing up to hundreds of thousands of concurrent API calls, including traffic management, authorization and access control, monitoring, and API version management.
Working with a microservices API gateway can greatly reduce coding efforts, make applications far more efficient. The benefits of Microservices architecture are realized over a period of time.
The concept is about building an application consisting of many small services that can be independently deployed and maintained. They own and do not share their data. They don’t have any dependencies but rather communicate with each other through lightweight mechanisms (typically not HTTP, but sockets) and lack a centralized infrastructure. It is even possible to write these small (micro-) services each in its own programing language. Diagram below compares at high level key difference between monolithic and micro-service architecture. Elastic infrastructure should help take away the issue of scalability across several microservices in the system.
It brings us to five key areas for Services, which are explained in following sections:
Service :- It is a technical authority for specific business capability. It should contain all data and business rules within it.
As we moved towards microservices architecture it becomes very important to define service capabilities.What a service can and cannot do.So in this section we will see how to define service boundaries and what are the attributes of a service.
Following are important points to keep in mind while defining a service
While it is said above that every service should have their own data, following rules may be observed in this context :
Enterprises may build multiple systems ,back-end, desktop, mobile, etc. accessing the same data. same services should provide their respective business capabilities for all of these systems. Although the systems may be built using different technologies and languages, they should share the same services.
Any service we write should have some kind of contract related to it.That contract should mention what is the input and output of that particular service.Services will share this contract between them and if any service violets this contract then it should be marked as invalid.
Lego based Infrastructure - Its the Future supporting the new Microservices Architecture
An event is a notable thing that happens inside or outside your business. An event (business or system) may signify a problem or impending problem, an opportunity, a threshold, or a deviation.
In an event-driven architecture, a notable thing happens inside or outside your business, which disseminates immediately to all interested parties (human or automated). The interested parties evaluate the event, and optionally take action. The event-driven action may include the invocation of a service, the triggering of a business process, and /or further information publication /syndication. Extreme Loose Coupling. By its nature, an event-driven architecture is extremely loosely coupled, and highly distributed. The creator (source) of the event only knows the event transpired. The creator has no knowledge of the event’s subsequent processing, or the interested parties. The traceability of an event through a dynamic multipath event network can be difficult. Thus, event-driven architectures are best used for asynchronous flows of work and information.
There are three general styles of event processing: simple, stream, and complex. The three styles are often used together in a mature event-driven architecture.
In simple event processing, a notable event happens, initiating downstream action(s). Simple event processing is commonly used to drive the real-time flow of work—taking lag time and cost out of a business.
In stream event processing, both ordinary and notable events happen. Ordinary events (orders, RFID transmissions) are both screened for notability and streamed to information subscribers. Stream event processing is commonly used to drive the real-time flow of information in and around the enterprise––enabling in-time decision making.
Complex event processing (CEP) deals with evaluating a confluence of events and then taking action. The events (notable or ordinary) may cross event types and occur over a long period of time. The event correlation may be casual, temporal, or spatial. CEP requires the employment of sophisticated event interpreters, event-pattern definition and matching, and correlation techniques. CEP is commonly used to detect and respond to business anomalies, threats, and opportunities.
Lets look at types of Event driven architecture
Types –> | WebSockets | WebHooks | Rest Hooks | Pub-Sub | Server Sent Events | ClientServer |
---|---|---|---|---|---|---|
Communication overheads | Low | Medium | Medium | Low | Low | High |
Duplex | Yes | Yes | Yes | Yes | No | No |
Throughput | High | High | High | High | High | Low |
Support in Browser | Yes | Yes | No | No | No | Yes |
Caching | No | Yes | Yes | No | No | Yes |
Scalability | No | Yes | Yes | Yes | No | Yes |
Loosely Coupled | No | No | No | Yes | No | No |
Com protocol | TCP | HTTP | HTTP | TCP | TCP | HTTP |
Examples | Notifications | GitHub | Radio Channel |
If system is built for scalability with low overhead in a browser environment, WebSockets are a great solution. Conversely, if those same benefits are needed in a non-browser system, then WebHooks should be selected. REST Hooks are not only great for RESTful services, they are also much easier to set up than either, and thus are great in low-time high-rush situations. Pub-Sub can be great if it requires to enforce a division between client and server, and this can further be established and controlled in an even stronger way with Server Sent events.
2.2.4.1 Websites
2.2.4.2 Videos
2.2.4.3 Gurus and Their Blogs
We can define developer experience as
Developer experience is the sum of all interactions and events, both positive and negative, between a developer and a library, tool, or API.
Developer can be of two types
For so long all the attention is on UX(user experience).While developing any API or service attention is primarily on end user, But most important people in all these process remains forgotten those are developers.For any organization to be successful it’s developers needs to be productive and they will be productive if they are happy with the tools, environment and overall culture given to them.
For example, If a developer is given an laptop with only 2GB of RAM and windows 7 on it, then he/ she won’t be able to install most of application he/ she wanted to, his/ her system will get slower over time and productivity automatically will reduce.This is perfect example of how bad developer experience can cost organization.
Another example would be developer have very low end server for development while prod has some other configuration.
Lets look developer Experience from an Open API perspective.As you write an API.It will get consumed by many people including APP developers or some other developers, so you need to write api in such a way that it can be understood by anyone.
Information, no matter how useful it is, won’t be consumed if the experience is not presented well, is not structured well, and is not interactive.
Moreover, An organization can run developer program which will take care of overall developer experience.
Context.IO has a pretty “high touch” approach to developer experience. Example :- https://context.io/
2.3.2.1 Websites
2.3.2.2 Videos
2.3.2.3 Gurus and Their Blogs
Public gateways or API gateways are becoming a must requirement because of the main reason - How do the clients of a Microservices-based application access the individual services?
Suppose in a monolithic application architecture, a mobile client want to retrieve some data. It would just hit some API URL. A load balancer routes the request to identical instance. In contrast, when using the microservice architecture, data is owned by multiple microservices, so client needs to hit multiple microservices to get required information.
Example -
A much better approach is to use API gateway. It is a server that is single entry point into the system. It encapsulates the internal system architecture and provide an API that is tailored to each client.
Example:-
The API gateway is responsible for request routing, composition and protocol translation. All request from clients first go through API gateway. It then routes requests to the appropriate microservice. The API Gateway will often handle a request by invoking multiple microservices and aggregating the results. It can translate between web protocols such as HTTP and Web Socket and web unfriendly protocols that are used internally.
The API gateway provides an endpoint that enables mobile client to retrieve all details with single request.
Another approach to build API gateway such that each client will have its own API gateway.
Example:-
(1) Access control- only allow authenticated and authorized traffic
(2) Rate limiting - restrict how much traffic is sent to your API
(3) Analytics, metrics and logging – track how your API is used
(4) Security filtering – make sure the incoming traffic is not an attack
(5) Redirection – send traffic to a different endpoint
The API Gateway is responsible for aggregating data and acting as a simple routing layer for appropriate services.The gateway works as a set of modules and filters which treat the traffic as it flows through it at high speed and we can control their parameters.The API gateway can be seen as a single point of failure. A better approach may be to create multiple API gateways.The Netflix API is the front door to that system, supporting over 1,000 different device types and handing over 50,000 requests per second during peak hours.
(1) Kong by Mashape
(2) Azure API Management by Microsoft
(3) Cloud Endpoints by Google(not full-fledged)
(4) API Gateway by Amazon
Performance and scalability -
For most applications the performance and scalability of the API Gateway is usually very important. There are a variety of different technologies that can be used to implement a scalable API Gateway. Example Node.js, which is a platform built on Chrome’s JavaScript engine.
Using a Reactive Programming Model -
Writing API code using the traditional asynchronous callback approach quickly leads you to callback hell. The code will be tangled, difficult to understand, and error prone. A much better approach is to write API Gateway code in a declarative style using a reactive approach. Example –Promises in JavaScript
Service Invocation
Microservice based application must use an inter-process communication mechanism. There are two styles of it. One is an asynchronous, messaging based mechanism. Examples - JMS or AMQP. Second one is a synchronous mechanism such as HTTP or Thrift.
Service Discovery
The API Gateway needs to know the location (IP address and port) of each microservice with which it communicates. In a traditional application, you could probably hardwire the locations, but in a modern, cloud based microservices application this is a nontrivial problem. API Gateway needs to use the system’s service discovery mechanism by querying System registry.
Handling Partial Failures
Another issue you have to address when implementing an API Gateway is the problem of partial failure. This issue arises in all distributed systems whenever one service calls another service that is either responding slowly or is unavailable. This kind of issue needs to be handled.
2.4.5.1 Websites
2.4.5.2 Videos
2.4.5.3 Gurus and Their Blogs
Blog - http://www.chrisrichardson.net/
2.5.1.1 Create a Separate Data Store for Each Microservice -
Do not use the same backend data store across microservices. You want the team for each microservice to choose the database that best suits the service. Breaking apart the data can make data management more complicated, because the separate storage systems can more easily get out sync or become inconsistent. You need to add tools for master-data-management.
2.5.1.2 Keep all code in a microservice at a similar level of maturity and stability -
If you need to add or rewrite some of the code in a deployed microservice that’s working well, the best approach is usually to create a new microservice for the new or changed code, leaving the existing microservice in place. This way you can iteratively deploy and test the new code until it is bug free and maximally efficient, without risking failure.
2.5.1.3. Deploy in Containers -
Deploying microservices in containers is important because it means you need just one tool to deploy everything. As long as the microservice is in a container, the tool knows how to deploy it. It doesn’t matter what the container is.Example - Docker
2.5.1.4. Treat Servers as Stateless -
Treat servers, particularly those that run customer facing code, as interchangeable members of a group. They all perform the same functions, so you don’t need to be concerned about them individually. Your only concern is that there are enough of them to produce the amount of work you need, and you can use auto scaling to adjust the numbers up and down.
Building complex applications is inherently difficult. A Monolithic architecture only makes sense for simple, lightweight applications. You will end up in a world of pain if you use it for complex applications. The Microservices architecture pattern is the better choice for complex, evolving applications despite the drawbacks and implementation challenges.
2.5.5.1 Websites
This whitepaper shows you how innovations from Amazon Web Services (AWS) can change how you can design multi-tiered architectures for popular patterns such as microservices, mobile back ends, and public websites. Architects and developers can now use an implementation pattern that includes Amazon API Gateway and AWS Lambda to reduce the development and operations cycles required to create and operationally manage multi-tiered applications.
2.5.5.2 Videos
2.5.5.3 Gurus and Their Blogs