no

Introduction to Api Composition Design Pattern

Go Back to Course Outline Introduction When dealing with 2 or more microservice, it’s often a problem to implement queries that join ...


Go Back to Course Outline

Introduction

  • When dealing with 2 or more microservice, it’s often a problem to implement queries that join data from multiple services.
  • For instance, we have a catalog and inventory microservice. The catalog provides the API in managing the catalog models such as product while inventory handles the stock of a certain product. In the inventory service, product data such as code is not maintained.
  • Now how do we generate a list of product stock with product code and quantity?
  • One answer is the API Composition Design Pattern.

Drawbacks and Solutions

  • This pattern is easy to use as we are just calling multiple microservices to get the data.
  • However, some queries can be inefficient as it might require pulling each record one by one. For example, if we have a list of 10 product stocks with different product id, that means we have to query the catalog service to get the product code 10x.
  • To avoid memory problems when loading a large dataset, always implement paging.
  • A view database can be created that will contain a summary of data from other databases for reporting purposes.

How can we create the view database?

  • If you are using the same database type such as Postgresql then you can simply join 2 tables from a different database.
  • Use Apache Nifi to populate a reporting table on a database whenever the source tables from different databases are modified.
  • Use a messaging queue such as Apache Kafka to update multiple databases.

Catalog and Inventory Microservice Architecture

The API Composer Class

Codes are available at Github

Related

spring-microservice 6314679673196089542

Post a Comment Default Comments

item