How grpc/grpc-swift-nio-transport works
Project Type and Purpose
• This is an open-source Swift library (a transport layer) implementing high-performance HTTP/2 client and server transports for gRPC Swift, built on top of SwiftNIO.
• It provides a modular, layered transport solution: a core transport abstraction, HTTP/2 framing layer, and platform-specific socket/TLS implementations, plus a C‐based zlib compressor.
Key Directories / Modules
• Sources/CGRPCNIOTransportZlib
• A small C library (zlib) and Swift headers for request/response compression.
• Sources/GRPCNIOTransportCore
• Core transport abstraction: connection management, load balancers, resolvers, stream handlers, message framing, compression protocol interfaces.
• Sources/GRPCNIOTransportHTTP2
• HTTP/2 framing and parsing, integrates with SwiftNIO’s NIOHTTP2.
• Sources/GRPCNIOTransportHTTP2Posix
• Posix socket bootstrap, NIOSSL integration, TLS config for client/server.
• Sources/GRPCNIOTransportHTTP2TransportServices
• Apple TransportServices bootstrap & TLS for non‐POSIX platforms.
• Tests / IntegrationTests
• Unit tests per module and end-to-end interop/performance tests using generated proto stubs.
• dev/
• Scripts for building, formatting, generating protos and running interop/perf tests.
How to Model This
• Application Layer (gRPC Swift client & server code)
• GRPCNIOTransportCore
– ConnectionManager, GRPCChannel, LoadBalancer, Resolver, StreamHandler, Compressor interface
• CGRPCNIOTransportZlib (zlib compressor/decompressor)
• GRPCNIOTransportHTTP2 (HTTP/2 frame encoder/decoder)
• Platform Transports (choose one at runtime):
– HTTP2TransportPosix (NIOSSL + Posix bootstrap)
– HTTP2TransportTransportServices (TransportServices + TLS)
• SwiftNIO Core
– EventLoopGroup, ChannelPipeline, NIOHTTP2Handler, SocketChannel
• Network (TCP/TLS, HTTP/2 wire)
1. Application → Core:
• Uses GRPCChannel API to open streams and send RPCs
2. Core → Compressor (optional):
• Invokes zlib via C interface for message compress/decompress
3. Core → HTTP2 Layer:
• Passes framed gRPC messages to HTTP2 encoder
4. HTTP2 Layer → Platform Transport:
• HTTP/2 frames enter ChannelPipeline with TLS handlers
5. Platform → SwiftNIO Socket:
• Bootstraps SocketChannel, applies TLS (NIOSSL or TransportServices)
6. Socket → Network:
• Over TCP/TLS carrying HTTP/2 frames
c. Architectural Patterns / Principles
• Layered modular design: Core transport, HTTP/2 framing, platform transport modules.
• Protocol-oriented abstractions (e.g., CompressionAlgorithm, NameResolver, LoadBalancer).
• Pipeline pattern (ChannelPipeline) for composable handlers (framing, TLS).
• Dependency injection of platform modules (Posix vs TransportServices).
d. Technologies & Frameworks
• SwiftNIO (EventLoopGroup, ChannelPipeline)
• NIOHTTP2 (HTTP/2 codec)
• NIOSSL or Apple TransportServices (TLS)
• zlib (C library for compression)
• Swift Package Manager (multi-module SPM)