In 2007, Facebook's engineers needed to integrate the various applications powering their website. As their engineering culture encouraged selecting the best tools for a task without imposing strict rules regarding the choice of technology, their applications were written in a wide spectrum of different programming languages, which were considered the best for the given task.
Looking for the best solution to fulfill their needs, the engineers reviewed lots of different frameworks that were already available on the market. None of them was deemed sufficient in terms of performance or flexibility. They made a decision to develop their own solution, which became a standard to integrate all the services on Facebook.
As they considered their solution to be exceeding the current standards of the market, they released their code to the open source community, passing the task of maintaining their work on the project to the Apache Software Foundation. Since then, Apache Thrift has been developed by a large group of volunteers.
Now you can use Apache Thrift as a tool to expose your own services that are written in different languages and make your applications communicate with each other. Regardless of whether you intend to work on a small-scale application or huge enterprise, Apache Thrift may be one of the best tools for you.
In Learning Apache Thrift, you will find an introduction to various concepts of the services around you and some service-oriented architecture (SOA). Then you will learn how to use Apache Thrift in various projects. We will discuss advanced concepts too to see how the giants of the industry use this framework, and you will get some solid advice and much needed inspiration.
Chapter 1, Introducing Apache Thrift, gives you basic information about the environment where services are needed. You will learn about the history of Apache Thrift and its position in the market. This chapter provides some solid understanding of the context in which Apache Thrift exists.
Chapter 2, Installing and Running Apache Thrift, provides you with a quick tutorial that will allow you to have Apache Thrift up and running on your machine in no time. Instructions for Linux (Debian and CentOS), Windows, and Mac OS X are included.
Chapter 3, Running Your First Apache Thrift Service and Client, gives you the ability to see Apache Thrift in action. Simple instructions will get you through the process of setting up a server and client that run in two different programming languages (PHP and Python) and communicate with each other.
Chapter 4, Understanding How Apache Thrift Works, provides you with real knowledge of the framework's internals. You will learn about its components, network stacks, data types, interface description language (IDL), and the programming languages that are supported. You will also find out about its limitations and how to deal with them. This chapter is essential to understand the concept of "under the hood", and how to design your own Apache Thrift-supported services.
Chapter 5, Generating and Running Code in Different Languages, provides you with a toolbox of essential information about different popular programming languages and how you can use them with Apache Thrift. You may read it from the beginning to the end or just focus on those languages that interest you. The same example is used for every language, so you can easily compare the server's and client's implementation for each of them.
Chapter 6, Handling Errors in Apache Thrift, gives you information on how to deal with undesirable situations that may occur when you run your service or client. Handling errors is an important part of any programming project, and is especially essential when dealing with cross-platform applications where errors occur frequently due to the nature of the distributed architecture.
Chapter 7, An Example Client-Server Application, gathers knowledge from the whole book into one example client-server application. You will build the code step by step. The example touches every aspect of Apache Thrift and is a bit more complicated than what you have done until now. Three different languages will be used (PHP, Python, and Ruby).
Chapter 8, Advanced Usage of Apache Thrift, inspires you to further expand your Apache Thrift skills. You will learn how big companies use this framework, how to run your applications in production, and how to address security, performance, and scalability issues. You will be also be given access to other interesting Apache Thrift-related projects.
To run the examples in this book, you will need any modern computer running Linux—CentOS or Debian (preferred)—Mac OS X, or Windows. You will also need some text editor to edit your code.
You will also need an Internet connection to download Apache Thrift and other required software on your computer.
If you have some experience of developing applications in one or more languages that are supported by Apache Thrift (C++, Java, PHP, Python, Ruby, and others) and want to broaden your knowledge and skills in building cross-platform, scalable applications, then this book is for you.
In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.
Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "It initializes the variable x
, which is an integer."
A block of code is set as follows:
int main() { int x = 42; // this line will produce compilation error x = "forty two"; return 0; }
Any command-line input or output is written as follows:
sudo apt-get update
New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "It varies from version to version, but in most cases may be found if you right-click on My Computer and choose Properties, then look for the Advanced panel and the Environment Variables… tab."
Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.
To send us general feedback, simply e-mail <[email protected]>
, and mention the book's title in the subject of your message.
If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.
Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.
You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.
To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.
Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.
Please contact us at <[email protected]>
with a link to the suspected pirated material.
We appreciate your help in protecting our authors and our ability to bring you valuable content.
If you have a problem with any aspect of this book, you can contact us at <[email protected]>
, and we will do our best to address the problem.