## 4 Logical Infrastructure of the Generated Metamodels
### Microservice Data Exchange Metamodel  
Microservice Data Exchange Metamodel includes data type definitions and the size of each element that is used for calculating communication costs among microservices. Although microservices are created independently, services need data exchange to form an application. This metamodel is designed to model data types and object sizes that microservices exchange between them. Different communication infrastructures such as Restful services, gRPC, etc., can be used for microservices. When we assess the level of datatype definition detail of alternative communication protocols, we see that the most comprehensive communication protocol in terms of data types is gRPC [26]. Since the gRPC protocol includes data types rich enough to model data exchange for all alternative communication patterns used for microservices, the data types belonging to gRPC proto3 [27] are used as the data type design foundation within the scope of this study.  
gRPC proto3 [27] covers many data types such as message, scalar value, nested, any, oneOf, etc. There are fifteen types of scalar value types such as double, float, byte, string, fixed32, int32, etc., and message type includes these scalar values. In addition to any, oneOf and maps data types can be used for unknown fields that the parser cannot recognize. As well as its comprehensive data types, gRPC is often preferred for microservices communication since it uses HTTP/2 transfer protocol and Protobuf encoding for efficient communication.  
Microservice Definition and Communication Metamodel enables defining microservices and creating communication patterns among microservices. This model includes four different classes named REST, graphQL, gRPC, publish/subscribe, and these are the communication protocols used for microservices. Enum classes such as graphQLEnum, PubSubTypeEnum, gRPCEnum, etc., are used for defining selection properties (e.g., for publish/subscribe communication: publish = 1, subscribe = 2) belong to communication protocols. To clarify the data exchanged by microservices, source microservice and target data should be selected through the developed tool. Target data is determined using the Microservice Data Exchange Metamodel described in the previous section. A sample Emfatic language written to establish a publish/subscribe relationship between microservices is shown in Algorithm 1.  
```
@gmf.link(source = \"source\", target = \"target\", target.decoration = \"arrow\",label = \"pubSubType\")
1: class PubSubRelation {
2: ref Microservice [1] source;
3: attr PubSubTypeEnum [1] pubSubType;
4: ref microDataExchangeModel.ObjectModelElement [1] target;
5: }
```  
**Algorithm 1** Sample Emfatic language for defining publish/subscribe relation.  
The PubSubRelation class, defined as a relation on the metamodel, determines the data published or subscribed by a microservice. Hence, it refers to Microservice class as a source link and ObjectModelElement class as a target link. For instance, in a microservice-based e-commerce application, suppose that the Order service subscribes to the UserInfo object, and this object is published by the Customer service. In this case, the source is selected as Order service, pubSubType type is selected as subscribe, and the target object derived from the ObjectModelElement class is selected as UserInfo. In the case that a source class is selected as Customer service, pubSubType is changed as publish.