We are developing a backend system for an airline company using Spring Boot. Our project requires us to integrate data from multiple APIs to generate flight rosters. Here is the current structure of our project:
src/
└── main/
└── java/com/su/FlightScheduler/
├── APIs/
│ ├── CabinCrewAPI/
│ ├── FlightAPI/
│ ├── PassengerAPI/
│ └── PilotAPI/
├── DTO/
├── Entity/
├── Repository/
├── Security/
├── Service/
└── FlightSchedulerApplication.java
Each API (Cabin Crew, Flight, Passenger, and Pilot) has its own controllers and services to perform CRUD operations. Now, we need to design the Main System that integrates the functionalities of these APIs to generate comprehensive flight rosters.
We are uncertain about the best approach to integrate these APIs within our main system. We are considering two approaches:
-
Calling the endpoints of each API from the main system:
The main system API would make HTTP requests to the endpoints of the other APIs to gather the necessary data. -
Using direct service communication:
The main system would directly invoke the service methods of the other APIs.
Which approach is generally recommended for such a scenario, and what are the best practices for implementing it? Are there other approaches we should consider? Any insights on maintaining modularity, performance, and ease of maintenance in such integrations would be highly appreciated.
Additional context:
- Our main system needs to provide different views for the flight roster (tabular view, plane view, and extended view).
- We are using Spring Boot for our application framework.
For now, we only completed the API’s aside from the main system API. So we actually did not wanted to start developing the main system before clearing this problem at our mind.
Kağan Becel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1
If All your APIs run within the same container there is no reason to use HTTP calls for them to communicate. So, definitely, call them directly.
However, be mindful of transaction management. Lets say you have some API end-point lets call it Call-A. It is exposed as REST endpoint and has controller and underlying service. However, besides being exposed as an independent end-point you also need to call it internally from your other endpoint (let’s call it Call-B). Here comes the question if you want entire logic of Call-B including invoking logic of Call-A to be a single transaction or do you want invocation of Call-A to be a separate transaction just as if it was called from outside? If you want it to be a single transaction then within Call-B invoke Call-A using its service (or even lover level BL class method if it is a single method). Else if you want Call-A logic be handled as a separate transaction then call it on Controller level (or even use an HTTP call to simulate external invocation)