REST model sharing between client and server

Consider two facts of a typical organization:

  • Some entities are very common (for example Order in a point of sale system)
  • Some entities may have complex relationships (for example Order could have a list of articles, a Payment method, the Address customer and such)

Suppose the organization has many micro-services (REST / json) and they all require the transfer of data of similar types.

For example. service 1 could receive a Order client, then send the same order to the service 2 that is processing the request, before sending the PaiementModdod to the client.

This means that it is possible to share the models between the different parties (customers and departments) involved, in cases where both are in the same language. Obviously, if they are not in the same language (or at least not in the same underlying platform), this might not be feasible. For example. Java / Scala is possible, but Java / JavaScript may not be it or result in additional costs associated with using a common descriptor or not.

Suppose that these can be easily shared and that this sharing would significantly reduce the time needed to create and maintain the exact same models in multiple locations, possibly including the surrounding code (for example, validation). Let me know if you feel that this assumption is not valid for any reason.

Some questions:

  • What are the disadvantages, if any, of sharing the model between the parties?
  • If the model is not to be shared, does this mean that we are duplicating almost the exact same entities (or at least the required subsets) in each part or are there better approaches?