Choosing RPC, gRPC, or Event APIs for Service Integration
Compare HTTP request-response, gRPC, and event APIs by interaction, streaming, compatibility, failure handling, and operational ownership.
HTTP request-response, gRPC, and event APIs give services different ways to coordinate work. Compare their contracts, streaming, compatibility, failures, and operating costs. Use an outbox when a database change and event publication must stay aligned, and plan for duplicate delivery at consumers.
Choosing RPC, gRPC, or Event APIs for Service Integration
Choose the interaction before the protocol. If checkout must tell a customer whether inventory was reserved, the caller needs a response. If analytics and fulfillment can react after an order is placed, an event can let them proceed independently.
REST-style HTTP, gRPC, and event APIs make different trade-offs in waiting, coupling, compatibility, and operations. None removes partial failures; each gives them a different boundary.
The three interaction styles
- HTTP request-response: A caller sends a request and waits for a response. It is widely supported by browsers, tools, and external clients.
- gRPC: A typed RPC contract, usually defined with Protocol Buffers, generates clients and servers. It supports unary calls and streaming RPCs. Teams need compatible code generation and a plan for schema changes.
- Event API: A producer publishes a fact or command for one or more consumers to process later. It decouples producer progress from consumer availability, but introduces lag, replay, ordering, and eventual consistency.
Do not choose gRPC just because binary messages sound faster, or choose events to avoid defining a synchronous contract. Measure performance only when it is a real constraint, using the same workload and deployment conditions.
Compare the contracts
| Concern | HTTP request-response | gRPC | Event API |
|---|---|---|---|
| Interaction | Caller waits for a response. | Caller waits for a unary result, or exchanges stream messages. | Producer publishes; consumers act independently, usually later. |
| Streaming | A regular endpoint is request-response; streaming needs a deliberate HTTP mechanism. | Client, server, and bidirectional streaming are part of the service model. | A broker delivers a sequence; ordering depends on partitions and consumers. |
| Compatibility | Define JSON fields, status codes, and a versioning policy. | Follow Protocol Buffers compatibility rules; do not reuse removed field numbers. | Define event schema evolution and how older consumers handle added or missing fields. |
| Failure handling | The caller needs deadlines and bounded retries; retries may repeat a completed operation. | Deadlines and status codes describe a call, but retry and cancellation rules still need configuration. | Plan for duplicate delivery, lag, replay, poison messages, and consumer recovery. |
| Operational ownership | Caller and provider teams share responsibility for the request path and deadline. | Client and server owners coordinate schema, generated code, deadlines, and runtime support. | Producer, broker, and consumer teams coordinate schema, retention, lag, replay, and dead-letter handling. |
The gRPC details follow the official core concepts guide. For protocol details, see the Protocol Buffers encoding guide and message update guidance. A schema file alone does not guarantee that old clients and new servers remain compatible; follow the rules for the tooling and versions you deploy.
Keep a database change and event publication aligned
Suppose an order service writes an order row and needs to publish OrderPlaced. Two separate actions create a dual-write failure: the database can commit while the broker publish fails, or the event can publish before the database transaction rolls back.
A transactional outbox writes the order change and an event row in the same database transaction. A relay publishes pending rows and records progress. The relay can publish twice if it crashes after the broker accepts an event but before it records that progress. Consumers still need a stable event ID and idempotent effects. The outbox aligns the service’s database write with its publication intent; it does not provide exactly-once delivery across the whole pipeline. See Transactional Outbox for relay and recovery details.
Choose by caller needs
Use HTTP request-response when the caller needs an immediate result or broad client compatibility. Choose gRPC when generated typed contracts or streaming matter and the client environments can support its tooling. Choose events when the producer and consumers can progress independently and eventual consistency is acceptable.
If the caller must know whether an operation happened, prefer a request-response contract with a clear idempotency and timeout policy. If work can happen later, publish an event and give consumers a replay and deduplication plan. Some systems use both: an RPC confirms an accepted command, and a later event reports the resulting fact.
Failure cases to plan for
| Failure | Design response |
|---|---|
| RPC times out after the provider completed the operation | Use an idempotency key or queryable operation ID before retrying. |
| gRPC client and server deploy incompatible schemas | Follow Protobuf compatibility rules and roll out schema changes in a compatible order. |
| A broker redelivers an event | Deduplicate by event ID and make the consumer effect idempotent. |
| Related events arrive out of order | Partition by aggregate or include sequence information and define how consumers handle gaps. |
| A browser cannot use the selected gRPC transport | Provide a supported gateway or use an HTTP contract for that client. |
For events, monitor publish failures, consumer lag, delivery attempts, and dead-letter counts. For RPC, track method latency, timeouts, and status codes. Correlate request and event IDs without logging secrets or personal data.
Further Reading
- Transactional Outbox — coordinate database changes with event publication.
- API Contracts — define compatibility rules for clients and services.
- Sync, Async Messaging, and Webhooks — compare delivery patterns.
- Partial Failure, Ordering, and Eventual Consistency — plan for delays and failures across services.
- gRPC core concepts — calls, streaming, deadlines, and service definitions.
- Protocol Buffers encoding and message updates — wire format and compatibility rules.
- AsyncAPI 3.0 specification — describe event-driven APIs and message channels.
- CloudEvents specification — common metadata for events.
Interview Questions
When producers and consumers can progress independently and the product accepts eventual consistency. The team must also support delivery, replay, ordering, and duplicate handling.
It records the domain change and the intent to publish in one database transaction. A relay sends the event later; consumers still need to tolerate duplicate publication and processing.
No. The client and server still need deadlines, bounded retries, cancellation behavior, and idempotency where a retry could repeat work.
Follow the Protobuf compatibility rules, keep old and new clients in mind during rollout, and never reuse a removed field number. Test with the generated code versions that will coexist.
Category
Related Posts
API Clients, Servers, and Network Boundaries Explained
Understand what API clients and servers each own, how network boundaries fail, and how timeouts, retries, and trust boundaries shape reliable integrations.
Idempotency, Deduplication, and Safe Replays
Design idempotent API operations and deduplication records so clients can retry after timeouts without creating duplicate payments, jobs, or updates.
Partial Failure, Ordering, and Eventual Consistency
Understand partial API failures, message ordering, and eventual consistency, then design status models and recovery paths clients can reason about.