Roadmap › Microservices & System Design with .NET › Module: Communication
Lessons in this course (9)
3. Synchronous communication — REST, gRPC and the API gateway
Intermediate★ Must knowLesson 3 of 9
| REST (HTTP + JSON) | gRPC (HTTP/2 + Protobuf) | |
|---|---|---|
| Contract | OpenAPI (optional) | .proto file (required, code-generated) |
| Payload | Text JSON — readable, larger | Binary — small and fast |
| Streaming | Limited (SSE, WebSockets) | Client, server and bidirectional streaming |
| Browser support | Native | Needs gRPC-Web |
| Best for | Public APIs, browser clients | Internal service-to-service calls |
csharp
// Typed HttpClient with built-in resilience (.NET 8+)
builder.Services.AddHttpClient<CatalogClient>(c => c.BaseAddress = new Uri("https+http://catalog"))
.AddStandardResilienceHandler(); // retry, circuit breaker, timeoutsAPI gateway — single entry point for clients: routing, TLS termination, authentication, rate limiting, request aggregation, caching. In .NET: YARP; in Azure: API Management or Application Gateway. Backend-for-Frontend (BFF): a gateway per client type (web, mobile) shaped for that client.
json
// YARP appsettings.json
"ReverseProxy": {
"Routes": { "orders": { "ClusterId": "orders", "Match": { "Path": "/api/orders/{**rest}" } } },
"Clusters": { "orders": { "Destinations": { "d1": { "Address": "http://orders-api:8080/" } } } }
}Danger: long synchronous call chains (A → B → C → D) multiply latency and failure probability. Prefer async messaging for anything that doesn't need an immediate answer.