Course contentsShow
← Software Engineering
Lesson 825 of 1,93325. RPC and GraphQL API DesignFree lesson

When to Choose RPC

Recognize when RPC suits your needs: action-oriented operations, internal services, and performance-critical systems.

When to Choose RPC

You'll learn: How to identify scenarios where RPC is the best API design choice for your system.


Core Idea

RPC (Remote Procedure Call) excels when you need to invoke actions rather than manipulate resources. Think of REST as organizing a library by books (resources), while RPC is like calling specific functions in someone else's program: "calculateTax", "sendEmail", or "processPayment". These are verbs—operations that do something—not nouns you're reading or updating.

When RPC Shines

1. Action-Oriented Operations
If your API is naturally a collection of commands or procedures, RPC fits perfectly. Operations like triggerBackup(), resetPassword(userId, token), or convertCurrency(amount, from, to) are awkward to force into REST's resource model. With RPC, you simply define the function and call it.

2. Internal Services (Microservices)
When building service-to-service communication inside your organization, RPC frameworks like gRPC offer strongly-typed contracts via IDLs. Your backend services can generate client code automatically, catching errors at compile-time rather than runtime. No human is reading these API calls—machines are—so REST's human-friendly URLs provide little value.

3. Performance-Critical Systems
RPC protocols like gRPC use binary serialization (Protocol Buffers) and HTTP/2, dramatically reducing payload size and latency compared to JSON over HTTP/1.1. If you're processing thousands of requests per second or sending data over constrained networks, RPC's efficiency is invaluable.

The Pattern

Choose RPC when you're building tools for machines to call functions, especially when speed matters and the operations don't map cleanly to CRUD on resources.

Key Takeaway:
Select RPC for action-oriented APIs, internal microservices communication, and performance-sensitive systems where efficiency and strong typing outweigh REST's resource-centric design.