Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

If you’re relatively new to the microservices, you’ll definitely want to read on. Even if you’re somewhat comfortable with microservices, you might want to skim this chapter: there will be a gem or two in here for you. If you’re a seasoned veteran of the microservice development, you can go ahead and move on to the next chapter (or read section. Or read on ironically and judge me)..

Microservices via APIs in Marionette Software

The most challenging aspect of working with APIs is ensuring that both the API client and the API server follow the API specification. Here we are going to explain you foundational patterns and principles for building Marionette microservices and driving their integrations with APIs. It is important to understand that an API is just a layer on top of an application, and that there are different types of interfaces.The advantages of microservices are many and varied. Many of these benefits can be , but looking past these challenges, the advantages of microservices are many and varied. Many of these benefits can be laid at the door of any distributed system. Microservices , however, tend to achieve these benefits to at a greater degree, primarily because they take a more opinionated stance in the way service boundaries are defined. By combining the concepts of information hiding and domain-driven design with the power of distributed systems, microservices help us deliver significant gains over other forms of distributed architectures. Microservices may well give us the option for each microservice to be written in a different programming language, to run on a different runtime , or to use a different database - but these are options only.

Marionette’s Microservices collaborate through APIs and further will overview how we apply GraphQL to organize APIs for these Microservices.

GraphQL APIs

Now that we where necessary.

Further we are going to explain the foundational patterns and principles for building Marionette microservices and driving their integrations with APIs. It is important to understand that an API is just a layer on top of an application, and that there are different types of interfaces. Understanding that Marionette’s Microservices interact through APIs, let’s review how we organize these APIs using GraphQL.

What is GraphQL?

Now that swe defined what an API is, we will explain let’s review the defining features of a that define web APIAPIs. A web API is an API that uses the Hypertext Transfer Protocol (HTTP) protocol to transport data. Web APIs are implemented using technologies such as SOAP, REST, GraphQL, gRPC, and others.
When a resource is represented by a large payload, fetching it from the server translates to a large amount of data transfer. With the emergence of API clients running in mobile devices with restricted network access and , limited storage and memory capacity, exchanging large payloads often results in unreliable communication.

In 2012, Facebook was acutely aware of these problems , and it developed a new technology to allow API clients to run granular data queries on the server. This technology was released open-source by Facebook in 2015 under the name of GraphQL.

GraphQL is a query language for APIs. Today, GraphQL is one of the most popular protocols for building web APIs. It’s a suitable choice for driving integrations between microservices and for building integrations with frontend applications. GraphQL gives API consumers full control over the data they want to fetch from the server and how they want to fetch it. GraphQL is a query language for APIs.

These are some of the reasons that make GraphQL an excellent choice for building the service API for Marionette. As we explain the specification for the trading APIs, we will also review scalar types of GraphQL, design of custom object types, as well as queries and mutations.

GraphQL for Managing Marionette’s APIs

Being a query language for API’s, GraphQL gives Marionette full control over API data we want to fetch from the server and full control over how we fetch this data. Instead of fetching full representations of resources, GraphQL allows us to fetch one or more properties of a resource, such as the order, or just the status of an order.

With GraphQL, we can also model Marionette models the relationship between different objects , which allows us to retrieve, and retrieves defined individual properties from various objects in a single request , the properties of various resources from the server, such as a orders’ details and others. In contrast, with other types of APIs, such as REST, you get a full list of details for each object. Therefore, whenever it’s important to give the client full control over how they fetch data Considering the important of control of how the data is fetched from the server, GraphQL is a great choiceclear choice for Marionette, but let’s take a deeper look.

For example, the trading : Trading service owns data about trades as well as their orders. Each trade and orders contains , each side of the order and a rich list of properties that describe their featuresthe extensive details of this trade. However, when a client requests the end-user requests to see a list of trades, they are most likely interested in fetching only a few details about each trade. Also, client (frontend) may be interested in being able Marionette operator will not display these extensive details to this user. It is best practice to only fetch the data they will relay to Frontend UI. Further, Marionette operator will often fetch data from various trading services to relay data the end-user is requesting to see on the Front-end. GraphQL offers the the ability to traverse the relationships between trades, orders, and other objects owned by the trading service. For these reasons, GraphQL is an excellent choice for building the service API. As we describe the specification for the trading API and others, you’ll learn about scalar types of GraphQL, design of custom object types, as well as queries and mutationsand do so with minimal server requests.

Just as we can use SQL to define schemas for our database tables, we can use GraphQL to write specifications that describe the type of data that can be queried from our servers. A GraphQL API specification is called a schema, and it’s written in a standard called Schema Definition Language (SDL).

...