HeadlinesBriefing favicon HeadlinesBriefing.com

gRPC vs REST for File Transfers

Hacker News: Front Page •
×

A technical blog post compares gRPC and REST for large file transfers, implementing both in C#. The author notes that while REST is straightforward, developers often buffer entire files in memory, risking out-of-memory errors. For gRPC, the solution involves chunking files into small messages, as its design buffers full messages, typically capped at 4 MB by default.

The implementation details show REST using `PhysicalFileResult` for direct streaming, whereas gRPC requires a server-streaming RPC that sends file metadata followed by byte chunks. A performance workaround uses `UnsafeByteOperations.UnsafeWrap` to avoid buffer copying. Testing was performed using Kreya, an API client, which needed custom scripting to reassemble chunks and preview the final PDF.

This exploration highlights practical trade-offs: REST is simpler for standard HTTP clients, while gRPC offers structured streaming but demands more complex client-side handling. The post leaves the performance comparison open, noting that factors like HTTP/2 and TLS affect wire efficiency. For developers, the choice hinges on whether the ecosystem's simplicity or the protocol's streaming capabilities are more valuable.