What is API Gateway Design Pattern?

What is API Gateway Design Pattern?

What is API Gateway Design Pattern?

Previously we saw about What is Microservice? and the principles followed while developing MSA and the available design patterns. also we saw an Aggregator design pattern.

Today we will see what is API Gateway Design Pattern is.

What is API Gateway Design Pattern?

Microservice is built in such a way that each service acts differently on its own. So, when a web application is drilled down into smaller pieces there could be problems we face.

The problems are as follows.

  1. How to get data from various microservices?
  2. A different front-end application is required to manage the same database, just that it uses multiple web services.
  3. How to respond with the data for different consumer to satisfy their requirement. So that we can have reusable microservices.
  4. Handle multiple protocol requests.

Seems the list is small here, but in reality, it is even wider. The solution for these problems is to use the API Gateway design pattern. The API Gateway design pattern addresses many other problems apart from the ones mentioned above. We can also use this design pattern as a proxy service for routing the request.

 API Gateway acts as the entry point for all the endpoints of the microservice, it can help in converting the various protocol request from one type to another. Also, it can disburden the responsibility of authentication/authorization in the microservice.

 So, once the client sends the request, requests are passed through the API gateway which manages the entry point and re-routes the client’s request to the appropriate microservice. Then with the help of the load balancer, it distributes the client’s request to the microservice.

Microservice uses the service discovery which maintains the available microservices and their available entry points to communicate with each other

What is API Gateway Design pattern?

API Gateway Design pattern

 

 

In the next article, we will see Chained or Chain of Responsibility design pattern.

 

LIKE | SHARE | SUBSCRIBE

WeCanCode-Author

WeCanCode-Author

November 06, 2021

Senior Developer | Java & C#.NET | 10++ years of IT experience.

Planning to learn ReactJS or Angular or Flutter.!

Know Aggregator Microservice Design Pattern

Know Aggregator Microservice Design Pattern

Aggregator Microservice Design Pattern

Previously we saw about What is Microservice? and the principles followed while developing MSA and the available design patterns.

Know about Microservice Aggregator Design Pattern.

Know Aggregator Microservice Design Pattern

The Aggregator is something that collects related items or data and displays them (combining and merging of data).

In MSA aggregator is a basic web service that internally invokes various services to get the required information that needs to be aggregated and send back to the requestor.

This pattern helps when you have the requirement of collecting data from various different services and merging the collected information.

aggregator microservice

Example:

We have two different services namely Student and Address which has their own database, and we need to gather the data from both the service/database.

Which uses a Unique ID as a reference in both databases, thus allowing us to fetch the data from both databases via the web service endpoint and combine or aggregate them with help of the new service Student’s Address which is the aggregator service.

 

 

In the next article, we will see in API Gateway design pattern.

 

LIKE | SHARE | SUBSCRIBE

WeCanCode-Author

WeCanCode-Author

November 05, 2021

Senior Developer | Java & C#.NET | 10++ years of IT experience.

Planning to learn ReactJS or Angular or Flutter.!

Difference between Entity vs Model

Difference between Entity vs Model

Difference between Entity vs Model

Entity: An entity represents a single instance of your domain object saved into the database as a record. It has some attributes that we represent as columns in our tables.

Model: A model typically represents a real world object that is related to the problem or domain space. In programming, we create classes to represent objects. These classes, known as models, have some properties and methods (defining objects behaviour).

ViewModel: The term ViewModel originates from the MVVM (Model View ViewModel) design pattern. There are instances in which the data to be rendered by the view comes from two different objects. In such scenarios, we create a model class which consists of all properties required by the view. It’s not a domain model but a ViewModel because, a specific view uses it. Also, it doesn’t represent a real world object.

DataModel: In order to solve a problem, objects interact with each other. Some objects share a relationship among them and consequently, form a data model that represents the objects and the relationship between them.

In an application managing customer orders, for instance, if we have a customer and order object then these objects share a many to many relationship between them. The data model is eventually dependent on the way our objects interact with each other. In a database, we see the data model as a network of tables referring to some other tables.

 

Pro Tip:

In any programming language always hide your entity object to the client. use model and mapper to share the object to the client.

WeCanCode-Author

WeCanCode-Author

August 05, 2021

Java & C#.NET Developer with 10++ years of IT experience.

Planning to learn ReactJS or Angular or Flutter.!

JAVA PROGRAM TO PRINT PATTERNS

JAVA PROGRAM TO PRINT PATTERNS

Interview Questions

Refer this for preparing yourself on how to write java program to print patterns (Note: NOT Design Patterns)
  • Start Pattern
  • Number Pattern

Star Pattern

 Print pattern like below, By giving the max length of the print.  (max. length is 5)
(max. length is 5)
public class StarPatternApp {
	public static void main(String[] args) {
		StarPatternApp.printPattern("*", 5);
	}
	private static void printPattern(String pattern, int size) {
		StringBuilder patternBuilder = new StringBuilder();
		for (int i = 1; i <= size; i++) {
			patternBuilder.append(pattern);
			System.out.println(patternBuilder.toString());
		}
		for (int i = size; i > 1; i--) {
			System.out.println(patternBuilder.deleteCharAt(i - 1).toString());
		}
	}

	private static String addSpaceAndPrint(int spaceCount, String printStr) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < spaceCount; i++) {
			sb.append("" + i);
		}
		sb.append(printStr);
        	return sb.toString();
	}
}

Number Pattern

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class NumberReducingPatternApp {

    public static void main(String[] args) {
       int n = 5;
       int length = 1;
       List<Integer> numberPatternItems = new ArrayList<>();
       for(int i=n; i>0;i--){
           numberPatternItems.add(listRangeInReverse(n,length));
           length++;
       }

       //This line actually reverst the entire list, so that the expected number pattern is printed
       Collections.reverse(numberPatternItems);
        for(Integer x: numberPatternItems){
            System.out.println(x);
        }
    }

    private static Integer listRangeInReverse(int k, int count) {
        StringBuilder sb = new StringBuilder();
        for (int c = k; c >=count;c--){
            sb.append(c);
        }
        return Integer.parseInt(sb.toString());
    }
}

Just a Note

There are N-ways of writing the above codes, please feel free to explore by playing around it.

Please disable your adblocker or whitelist this site! We Provide Free content and in return, all we ask is to allow serving Ads.

Pin It on Pinterest