We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Api Design Protocols
Free preview: the first 2 parts of this 6-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Api Design Protocols
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
It is easy and good
“It is really nice and good Please join the course”
Before existed, Facebook needed services written in different languages to communicate efficiently. PHP for the web frontend, C++ for performance-critical backends, Java for data processing, Python for ML models. They built Apache Thrift in 2007 to solve this.
Thrift is both a serialization format (like Protobuf) and an RPC framework (like gRPC). You define services in an IDL (Interface Definition Language), generate client/server code in 20+ languages, and pick from multiple transport protocols (HTTP, , Unix sockets) and serialization formats (binary, compact, JSON). That flexibility is Thrift's defining characteristic.
Facebook (now Meta) still runs Thrift at massive scale internally. Their Thrift-based RPC handles hundreds of billions of calls per day across their data centers. Apache Cassandra originally used Thrift as its client protocol (before switching to CQL). Evernote's API was Thrift-based. Various financial institutions use Thrift where raw TCP transport offers lower latency than /2.
For new projects in 2024+, gRPC has largely won the mindshare battle. But Thrift's architectural ideas, particularly the layered transport/protocol separation, remain influential. Understanding Thrift helps you understand why gRPC made the design trade-offs it did.
namespace java com.example.orders
namespace py orders
struct Order {
1: required string id,
2: required string customerId,
3: required double total,
4: optional string note,
5: list<LineItem> items,
}
exception NotFoundException {
1: string message,
}
service OrderService {
Order getOrder(1: string orderId) throws (1: NotFoundException e),
void createOrder(1: Order order),
list<Order> listOrders(1: i32 limit, 2: i32 offset),
}
Notice the field numbers (1, 2, 3). Same concept as Protobuf. Also notice required, optional, and the throws clause for exceptions. Thrift's IDL is more expressive than Protobuf's, though proto3 has caught up on most features.
The Thrift compiler generates code for the specified namespaces: Java classes in com.example.orders, Python classes in the orders module. Each generated client handles connection management, serialization, and error mapping.
Thrift's unique selling point is mix-and-match:
You can run a Compact protocol over raw TCP for maximum performance, or switch to JSON over for debugging, without changing a single line of service code.