ArticleslgStudy

computer science

Apache Thrift

Apache Thrift is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Apache Thrift rather than just read about it. In short: Thrift is an interface definition language and binary communication protocol used for defining and creating services for programming languages. It was developed by Facebook.

Apache Thrift — main illustration
Apache Thrift — illustration

Key takeaways

  • Apache Thrift belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Apache Thrift to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Apache Thrift from memory before moving on to harder problems.

Reference excerpt

Thrift is an interface definition language and binary communication protocol used for defining and creating services for programming languages. It was developed by Facebook. Since 2008, it is an open source project in the Apache Software Foundation. It uses a remote procedure call (RPC) framework and combines a software stack with a code generation engine to build cross-platform services. Thrift can connect applications written in a variety of languages and frameworks, including ActionScript, C, C++, C#, Cocoa, Delphi, Erlang, Go, Haskell, Java, JavaScript, Objective-C, OCaml, Perl, PHP, Python, Ruby, Elixir, Rust, Scala, Smalltalk, and Swift. The implementation was described in an April 2007 technical paper released by Facebook, now hosted on Apache.

Architecture

Thrift includes a complete stack for creating clients and servers. The top part is generated code from the Thrift definition. From this file, the services generate client and processor codes. In contrast to built-in types, created data structures are sent as a result of generated code. The protocol and transport layer are part of the runtime library. With Thrift, it is possible to define a service and change the protocol and transport without recompiling the code. Besides the client part, Thrift includes server infrastructure such as blocking, non-blocking, and multi-threaded servers. The underlying I/O part of the stack is implemented differently for different programming languages. Thrift supports a number of protocols:

TBinaryProtocol – A binary format not optimized for space efficiency. Faster to process than the text protocol. TCompactProtocol – More compact binary format. TJSONProtocol – Uses JSON for the encoding of data. TSimpleJSONProtocol – A write-only protocol that cannot be parsed by Thrift because it drops metadata using JSON. Suitable for parsing by scripting languages. The supported transports are:

TSimpleFileTransport – This transport writes to a file. TFramedTransport – This transport is required when using a non-blocking server. It sends data in frames, each preceded by length information. TMemoryTransport – Uses memory for I/O. The Java implementation uses a simple ByteArrayOutputStream internally. TSocket – Uses blocking socket I/O for transport. TZlibTransport – Performs compression using zlib. Used in conjunction with another transport. Thrift also provides a number of servers, which are:

TNonblockingServer – A multi-threaded server using non-blocking I/O (Java implementation uses NIO channels). TFramedTransport must be used with this server. TSimpleServer – A single-threaded server using standard blocking I/O. TThreadedServer – A multi-threaded server using a thread per connection model and standard blocking I/O. TThreadPoolServer – A multi-threaded server using a thread pool and standard blocking I/O. Thrift is written in C++, but can create code for some other programming languages. To create a Thrift service, one has to write Thrift files that describe it, generate the code in the destination language, write some code to start the server, and call it from the client. An example of such a description file:

Thrift will generate the code out of this descriptive information. For instance, in Java, the PhoneType will be enum inside the Phone class.

See also

References

External links Official website

Worked examples

Example 1 — a first encounter with Apache Thrift

Start with the simplest possible case. Write down what Apache Thrift claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Apache Thrift before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Apache Thrift ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Apache Thrift

In research
Apache Thrift appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Apache Thrift in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Apache Thrift is common in secondary-school and first-year university syllabi. It links to neighbouring topics Apache Software Foundation projects, Application layer protocols, Data serialization formats, so understanding it makes those chapters shorter.
In everyday life
Look for Apache Thrift outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Apache Thrift” →

How to study Apache Thrift in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Apache Thrift means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Apache Thrift out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Apache Thrift in simple terms?

Thrift is an interface definition language and binary communication protocol used for defining and creating services for programming languages. It was developed by Facebook.

Why does Apache Thrift matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Apache Thrift?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Apache Thrift.

Tags

  • Apache Software Foundation projects
  • Application layer protocols
  • Data serialization formats
  • Facebook software
  • Inter-process communication
  • Remote procedure call

Keep exploring