gRPC Go for Professionals

Book description

Build robust, production-ready microservices in gRPC Go to enhance the scalability and efficiency of your APIs in real-world applications Purchase of the print or Kindle book includes a free PDF eBook

Key Features

  • Discover essential guidelines to steer clear of pitfalls when designing and evolving your gRPC services
  • Develop your understanding of advanced gRPC concepts such as authentication and security
  • Put your knowledge into action as you build, test, and deploy a TODO list microservice

Book Description

In recent years, the popularity of microservice architecture has surged, bringing forth a new set of requirements. Among these, efficient communication between the different services takes center stage, and that's where gRPC shines. This book will take you through creating gRPC servers and clients in an efficient, secure, and scalable way. However, communication is just one aspect of microservices, so this book goes beyond that to show you how to deploy your application on Kubernetes and configure other tools that are needed for making your application more resilient. With these tools at your disposal, you’ll be ready to get started with using gRPC in a microservice architecture.

In gRPC Go for Professionals, you'll explore core concepts such as message transmission and the role of Protobuf in serialization and deserialization. Through a step-by-step implementation of a TODO list API, you’ll see the different features of gRPC in action. You’ll then learn different approaches for testing your services and debugging your API endpoints. Finally, you’ll get to grips with deploying the application services via Docker images and Kubernetes.

What you will learn

  • Understand the different API endpoints that gRPC lets you write
  • Discover the essential considerations when writing your Protobuf files
  • Compile Protobuf code with protoc and Bazel for efficient development
  • Gain insights into how advanced gRPC concepts work
  • Grasp techniques for unit testing and load testing your API
  • Get to grips with deploying your microservices with Docker and Kubernetes
  • Discover tools for writing secure and efficient gRPC code

Who this book is for

Whether you’re interested in microservices or looking to use gRPC in your product, this book is for you. To fully benefit from its contents, you’ll need a solid grasp of Go programming and using a terminal. If you’re already familiar with gRPC, this book will help you to explore the different concepts and tools in depth.

Table of contents

  1. gRPC Go for Professionals
  2. Contributors
  3. About the author
  4. About the reviewers
  5. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the example code files
    5. Download the color images
    6. Conventions used
    7. Get in touch
    8. Share Your Thoughts
    9. Download a free PDF copy of this book
  6. Chapter 1: Networking Primer
    1. Prerequisites
    2. Understanding HTTP/2
    3. RPC operations
      1. Send Header
      2. Send Message
      3. Send Half Close
      4. Send Trailer
    4. RPC types
      1. Unary
      2. Server streaming
      3. Client streaming
      4. Bidirectional streaming
    5. The life cycle of an RPC
      1. The connection
      2. The client side
      3. The server side
    6. Summary
    7. Quiz
    8. Answers
  7. Chapter 2: Protobuf Primer
    1. Prerequisites
    2. Protobuf is an IDL
    3. Serialization and deserialization
    4. Protobuf versus JSON
      1. Serialized data size
      2. Readability
      3. Schema strictness
    5. Encoding details
      1. Fixed-size numbers
      2. Varints
      3. Length-delimited types
      4. Field tags and wire types
    6. Common types
      1. Well-known types
      2. Google common types
    7. Services
    8. Summary
    9. Quiz
    10. Answers
  8. Chapter 3: Introduction to gRPC
    1. Prerequisites
    2. A mature technology
    3. What is gRPC doing?
      1. The server
      2. The client
    4. The read/write flow
    5. Why does gRPC matter?
      1. REST
      2. GraphQL
      3. Comparison with gRPC
    6. Summary
    7. Quiz
    8. Answers
  9. Chapter 4: Setting Up a Project
    1. Prerequisites
    2. Creating a .proto file definition
    3. Generating Go code
      1. Protoc
      2. Buf
      3. Bazel
    4. Server boilerplate
      1. Bazel
    5. Client boilerplate
      1. Bazel
    6. Server and Dial options
      1. grpc.Creds
      2. grpc.*Interceptor
    7. Summary
    8. Quiz
    9. Answers
  10. Chapter 5: Types of gRPC Endpoints
    1. Technical requirements
    2. Using the template
    3. A Unary API
      1. Code generation
      2. Inspecting the generated code
      3. Registering a service
      4. Implementing AddTask
      5. Calling AddTask from a client
      6. Bazel
    4. The server streaming API
      1. Evolving the database
      2. Implementing ListTasks
      3. Calling ListTasks from a client
    5. The client streaming API
      1. Evolving the database
      2. Implementing UpdateTasks
      3. Calling UpdateTasks from a client
    6. The bidirectional streaming API
      1. Evolving the database
      2. Implementing DeleteTasks
      3. Calling UpdateTasks from the client
    7. Summary
    8. Quiz
    9. Answers
  11. Chapter 6: Designing Effective APIs
    1. Technical requirements
    2. Choosing the right integer type
      1. An alternative to using integers
    3. Choosing the right field tag
      1. Required/optional
      2. Splitting messages
      3. Improving UpdateTasksRequest
    4. Adopting FieldMasks to reduce the payload
      1. Improving ListTasksRequest
    5. Beware the unpacked repeated field
      1. Packed repeated fields
      2. Unpacked repeated fields
    6. Summary
    7. Quiz
    8. Answers
  12. Chapter 7: Out-of-the-Box Features
    1. Technical requirements
    2. Handling errors
      1. Bazel
    3. Canceling a call
    4. Specifying deadlines
    5. Sending metadata
    6. External logic with interceptors
    7. Compressing the payload
    8. Securing connections
      1. Bazel
    9. Distributing requests with load balancing
    10. Summary
    11. Quiz
    12. Answers
    13. Challenges
  13. Chapter 8: More Essential Features
    1. Technical requirements
    2. Validating requests
      1. Buf
      2. Bazel
    3. Middleware = interceptor
    4. Authenticating requests
      1. Bazel
    5. Logging API calls
    6. Tracing API calls
      1. Bazel
    7. Securing APIs with rate limiting
      1. Bazel
    8. Retrying calls
      1. Bazel
    9. Summary
    10. Quiz
    11. Answers
    12. Challenges
  14. Chapter 9: Production-Grade APIs
    1. Technical requirements
    2. Testing
      1. Unit testing
      2. Load testing
    3. Debugging
      1. Server reflection
      2. Using Wireshark
      3. Turning gRPC logs on
    4. Deploying
      1. Docker
      2. Kubernetes
      3. Envoy proxy
    5. Summary
    6. Quiz
    7. Answers
    8. Challenges
  15. Epilogue
  16. Index
    1. Why subscribe?
  17. Other Books You May Enjoy
    1. Packt is searching for authors like you
    2. Share Your Thoughts
    3. Download a free PDF copy of this book

Product information

  • Title: gRPC Go for Professionals
  • Author(s): Clément Jean
  • Release date: July 2023
  • Publisher(s): Packt Publishing
  • ISBN: 9781837638840