Thursday, July 3, 2025

Client-Side Streaming gRPC : A Real-World File Upload Example

This project demonstrates client-side streaming using gRPC with a Spring Boot application. It includes:

  • A gRPC server that receives file chunks via stream and reconstructs them.

  • A REST client that accepts multipart/form-data uploads and streams the file to the server over gRPC.

πŸ”§ Technologies Used

  • Java 11
  • Spring Boot 2.7.x
  • gRPC (1.54.0)
  • Protocol Buffers (proto3)
  • Maven
  • WebFlux + Server-Sent Events (SSE) for REST integration

βœ…Code Repository LinkΒ 

LinkΒ -Β grpc-client-streaming

1. Start gRPC Server

  • cd grpc-client-streaming-upload-server mvn spring-boot:run

2. Start REST Client

  • cd grpc-client-streaming-upload-client mvn spring-boot:run

3. Upload a File via REST

  • curl -X POST http://localhost:8080/upload -H "Content-Type: multipart/form-data" -F "file=@/path/to/your/file.txt"

βœ… Project Structure

Server: grpc-client-streaming-upload


  • grpc-client-streaming-upload/ β”œβ”€β”€ src/ β”‚ └── main/ β”‚ β”œβ”€β”€ java/com/example/grpc/ β”‚ β”‚ β”œβ”€β”€ GrpcApplication.java # Spring Boot main class β”‚ β”‚ └── FileUploadService.java # gRPC service implementation β”‚ β”œβ”€β”€ proto/upload.proto # gRPC service and message definitions β”‚ └── resources/application.properties # gRPC + HTTP port config └── pom.xml # Maven config with protobuf plugin

Client: grpc-client-streaming-upload-client


  • grpc-client-streaming-upload-client/ β”œβ”€β”€ src/ β”‚ └── main/ β”‚ β”œβ”€β”€ java/com/example/grpc/ β”‚ β”‚ β”œβ”€β”€ GrpcClientApplication.java # Spring Boot main class β”‚ β”‚ └── FileUploadController.java # REST endpoint that calls gRPC client β”‚ β”œβ”€β”€ proto/upload.proto # Same proto for stub generation β”‚ └── resources/application.properties # gRPC target address config └── pom.xml # Maven config with protobuf plugin

πŸ” Quick Explanation of Key Classes


🧬 Proto File 


  • syntax = "proto3";
    option java_multiple_files = true;
    option java_package = "com.example.grpc";
    option java_outer_classname = "FileUploadProto";
    service FileUploader {
    rpc UploadFile (stream FileChunk) returns (UploadStatus);
    }
    message FileChunk {
    string filename = 1;
    bytes content = 2;
    }
    message UploadStatus {
    bool success = 1;
    string message = 2;
    }


πŸ” Diagram: REST β†’ gRPC Flowe


  • [User/Client] ──HTTP/POST──> REST Controller (Spring Boot) └──▢ Reads multipart file └──▢ Opens gRPC stream └──▢ Sends file chunks └──▢ gRPC Server handles each chunk └──▢ On complete, sends UploadStatus

βœ… When to Use gRPC Client-Side Streaming

🚫 Anti-Patterns / When Not to Use It

🚫 gRPC Anti-Patterns & When Not to Use It


πŸš€ gRPC Streaming Performance Comparison

You may also like

Kubernetes Microservices
Python AI/ML
Spring Framework Spring Boot
Core Java Java Coding Question
Maven AWS