Junior — Middle
How is information exchanged between microservices in synchronous mode?
sobes.tech AI
Answer from AI
Communication between microservices in synchronous mode is usually carried out via HTTP requests, most often using REST API or gRPC. One service sends a request to another and waits for a response, ensuring direct and immediate communication.
Example in Python using the requests library to call another microservice's REST API:
import requests
response = requests.get('http://service-b/api/data')
if response.status_code == 200:
data = response.json()
print(data)
else:
print('Request error')
This approach is convenient when you need to get data or the result of an operation immediately, but it can lead to delays and reduced fault tolerance in case of network or recipient service issues.