Real World Example

How Big Companies Call Each Other

CompanyExample callProtocol
NetflixPlayback API asks the licence service if a title can play in IndiagRPC / REST, plus their own client libraries
AmazonCheckout asks the pricing and inventory services before chargingInternal service APIs
UberTrip service asks pricing for a fare quotegRPC (Protobuf contracts)
SwiggyCart asks the restaurant service if the outlet is openREST/gRPC + Kafka events

Note: Every one of these calls has a timeout, an error mapping and usually a fallback. Swiggy shows "Restaurant currently not accepting orders" instead of an error page when the call fails.

Swiggy-Style Check Before Checkout

@Component
public class RestaurantClient {
    private final RestClient restClient;

    public RestaurantClient(RestClient.Builder builder,
                            @Value("${services.restaurant-url}") String url) {
        this.restClient = builder.baseUrl(url).build();
    }

    public record Availability(Long restaurantId, boolean open, int prepMinutes) {}

    public Availability availability(Long restaurantId) {
        return restClient.get()
                .uri("/api/restaurants/{id}/availability", restaurantId)
                .retrieve()
                .body(Availability.class);
    }
}

Example

cart-service checks availability before showing the "Place Order" button:

curl localhost:8090/api/restaurants/42/availability

Example output

{"restaurantId":42,"open":true,"prepMinutes":18}

ShopEase After This Module

client --> order-service :8082 --RestClient--> product-service :8081
              |   timeouts 2s/3s                    |
              |   404 -> 404, 409 -> 409            |
              |   down -> 503                       |
           order_db                             product_db

Next: hard-coded URLs and many entry points do not scale.
      Spring Cloud adds discovery, a gateway and central config.