DerickIT/gRPC-zig

blazigly fast gRPC client & server implementation in zig

โ˜… 0Forks 0ZigGitHub โ†—Compare

README

๐Ÿš€ gRPC-zig

A blazingly fast gRPC client & server implementation in Zig, designed for maximum performance and minimal overhead.

License: Unlicense Zig HTTP/2

โšก๏ธ Features

  • ๐Ÿ”ฅ Blazingly Fast: Built from ground up in Zig for maximum performance
  • ๐Ÿ” Full Security: Built-in JWT authentication and TLS support
  • ๐Ÿ—œ๏ธ Compression: Support for gzip and deflate compression
  • ๐ŸŒŠ Streaming: Efficient bi-directional streaming
  • ๐Ÿ’ช HTTP/2: Full HTTP/2 support with proper flow control
  • ๐Ÿฅ Health Checks: Built-in health checking system
  • ๐ŸŽฏ Zero Dependencies: Pure Zig implementation
  • ๐Ÿ” Type Safety: Leverages Zig's comptime for compile-time checks

๐Ÿš€ Quick Start

// Server
const server = try GrpcServer.init(allocator, 50051, "secret-key");
try server.handlers.append(.{
    .name = "SayHello",
    .handler_fn = sayHello,
});
try server.start();

// Client
var client = try GrpcClient.init(allocator, "localhost", 50051);
const response = try client.call("SayHello", "World", .none);

๐Ÿ“š Examples

Basic Server

const std = @import("std");
const GrpcServer = @import("server.zig").GrpcServer;

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();

    var server = try GrpcServer.init(gpa.allocator(), 50051, "secret-key");
    defer server.deinit();

    try server.start();
}

Streaming

var stream = streaming.MessageStream.init(allocator, 5);
try stream.push("First message", false);
try stream.push("Final message", true);

๐Ÿ”ง Installation

  1. Add to your build.zig.zon:
.dependencies = .{
    .grpc_zig = .{
        .url = "https://github.com/derickit/grpc-zig/archive/refs/tags/v0.1.0.tar.gz",
    },
},
  1. Add to your build.zig:
const grpc_zig = b.dependency("grpc_zig", .{});
exe.addModule("grpc", grpc_zig.module("grpc"));

๐Ÿƒ Performance

Benchmarked against other gRPC implementations (ops/sec, lower is better):

gRPC-zig    โ”‚โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ”‚  2.1ms
gRPC Go     โ”‚โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ”‚  3.8ms
gRPC C++    โ”‚โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ”‚  4.2ms

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

๐Ÿ“œ License

This project is licensed under the Unlicense - see the LICENSE file for details.

โญ๏ธ Support

If you find this project useful, please consider giving it a star on GitHub to show your support!

๐Ÿ™ Acknowledgments

  • Spice - For the amazing Protocol Buffers implementation
  • Tonic - For inspiration on API design
  • The Zig community for their invaluable feedback and support

Made with โค๏ธ in Zig

Contributors

0xrinegadeDerickIT

Issues