Java Design Architecture – Which Layer Should Communicate with Third Party?

Architecturedesignjava

We have multiple layered architecture

UI --> Application Layer --> Business Layer --> DB

There is a third party services that we are communicating with. If Business layer communicates to Third party service, then it has the advantage of making our Application layer light weight and at the same time there is data passing through an extra layer. Which layer Application or Business should communicate to that third party service and Why ?

Best Answer

The the-onion-architecture defines interfaces to external services in their domain-layer (you call it Busines-Layer) and the implementation of the service into a seperate service layer. This way busineslayer and other services can use all service-interfaces without depending on the service implementation.

your architecture will look like this:

 UI --> Application Layer --> Business Layer --> Service-Interfaces
 Service-Implementation --> Business Layer --> Service-Interfaces

i.e.

 WebOrder-Service-Implementation --> Order Business Layer --> Database Service-Interface

So to anwer your question:

> Which layer should communicate to third party?

Only the third-party-service-implementation and nobody else.

All other modules only communicate with the third-party-service-interface