Join Samuel Pereira at Elixir Meetup #11 with the topic of gRPC, comparing it with REST and demonstrating how to implement gRPC in Elixir. It's for developers looking to optimize communication between microservices and improve app performance.

Table of contents

    About Samuel Pereira

    Samuel Pereira is a passionate Elixir developer from Brazil with nearly two years of experience. He enjoys exploring the functional programming paradigm and has a keen interest in optimizing backend communication. In his free time, Samuel likes to watch horror movies and play Xbox.

    Understanding gRPC and Its Benefits

    What is gRPC?

    Samuel begins by explaining gRPC, which stands for Google Remote Procedure Call. gRPC is an open-source framework developed by Google in 2015, designed to enable remote procedure call-style communication. It is a modern implementation of RPC, addressing today's communication challenges.

    Key Features of gRPC:

    • HTTP/2 Protocol: Uses HTTP/2, offering lower latency and better performance compared to HTTP/1.1.
    • Binary Data Transmission: Transmits data as bytes, resulting in smaller payloads and faster parsing.
    • Streaming Support: Supports client, server, and bi-directional streaming.
    • Language Independent: Allows communication between services written in different programming languages using protocol buffers (protobufs).

    Comparing gRPC with REST

    Differences Between gRPC and REST

    Samuel compares gRPC with REST, highlighting key differences and advantages of gRPC over REST.

    Key Differences:

    • Data Format: REST typically uses JSON, whereas gRPC uses binary data, reducing payload size and improving peed.
    • Communication Patterns: REST is unidirectional and synchronous, while gRPC supports bi-directional and asynchronous communication.
    • Latency: gRPC offers lower latency due to HTTP/2 and binary data transmission.
    • Contract Enforcement: gRPC enforces a strict contract through proto files, ensuring consistent communication between services.

    Implementing gRPC in Elixir

    Setting Up gRPC in Elixir

    Samuel demonstrates how to set up gRPC in an Elixir project. He explains the steps to install the necessary dependencies and configure the application.

    Setup Steps:

    1. Install Protobuf: Follow instructions to install protobuf for your operating system.
    2. Add Dependencies: Include gRPC and protobuf dependencies in your Elixir project.
    3. Define Proto File: Create a proto file to define service methods and data structures.
    4. Transpile Proto File: Transpile the proto file to generate Elixir modules.

    Practical gRPC Application

    Example: Get User Service

    Samuel walks through a basic example of a Get User service, showcasing how to define a proto file, implement the server, and create a client to make requests.

    Example Highlights:

    • Proto File Definition: Define the service methods and data structures.
    • Server Implementation: Set up the server to handle incoming requests.
    • Client Implementation: Create a client to make requests to the server.

    Advantages and Challenges of gRPC

    Advantages of gRPC

    Samuel summarizes the advantages of using gRPC over REST, including improved performance, lower latency, and better efficiency in handling large payloads.

    Key Advantages:

    • Performance: 7-10 times faster than REST.
    • Efficiency: Smaller payloads reduce bandwidth usage.
    • Streaming Support: Enables real-time communication and data streaming.

    Challenges of gRPC

    Despite its advantages, gRPC also has some challenges, such as limited browser support and a steeper learning curve compared to REST.

    Key Challenges:

    • Browser Support: No native support for gRPC in browsers.
    • Learning Curve: Requires understanding of proto files and binary data transmission.
    • Language Support: Official support for fewer languages compared to REST.

    Conclusion

    Samuel Pereira's presentation at Elixir Meetup #11 offers a comprehensive overview of gRPC, its advantages over REST, and practical steps to implement gRPC in Elixir. By leveraging gRPC, developers can enhance communication between microservices, improve performance, and reduce latency.

    Join the Community

    Ready to explore the reliability of Elixir and Erlang?

    Register for the next Elixir Meetup at Curiosum Meetups: Registration Join our community of Elixir enthusiasts at Elixir LinkedIn Group Prefer watching the presentation? Here’s the video

    Mikołaj Musioł Recruitment Specialist
    Mikołaj Musioł IT Recruitment & HR Specialist

    Read more
    on #curiosum blog

    Bringing SOLID to Elixir

    Bringing SOLID to Elixir

    The SOLID principles, originally designed for object-oriented programming, can also be adapted effectively to functional programming languages like Elixir. Read how to apply it to create more maintainable, scalable, and adaptable software systems.