Backend Development 9 min read

Why Dubbo Is Unsuitable for File Transfer and How HTTP/Feign Handles It

The article explains why Dubbo's RPC design and single‑connection model make it inefficient for transmitting files, compares the memory‑heavy approach of sending byte arrays with the streaming nature of HTTP, and shows how Feign can upload files but still suffers from in‑memory buffering.

Java Architect Essentials
Java Architect Essentials
Java Architect Essentials
Why Dubbo Is Unsuitable for File Transfer and How HTTP/Feign Handles It

In a previous project a Dubbo service wrapped Tencent Cloud's object storage SDK to centralize third‑party SDK usage, but the author discovered that using Dubbo to transfer files is a bad idea because Dubbo serializes objects and cannot directly handle File objects.

Dubbo can only transmit the raw file content, e.g. void sendPhoto(File photo); must be changed to void sendPhoto(byte[] photo); . This forces the consumer to load the entire file into memory, and the provider must also deserialize the whole byte[] , leading to excessive memory consumption.

Additionally, Dubbo's default protocol uses a single TCP connection per provider. All requests share this connection, and Netty queues write events. When a large file (or any large payload) is sent, the channel is blocked by that single massive write, causing other requests to wait and eventually time out.

The single‑connection design is chosen to save resources: most services have few providers and many consumers, so a single long‑lived connection reduces handshake overhead and avoids the C10K problem. Dubbo does allow multiple connections via configuration, e.g. <dubbo:service connections="1"/> and <dubbo:reference connections="1"/> , which uses a round‑robin pool of connections per provider.

HTTP, on the other hand, is naturally suited for file transfer because a client can read a file in small buffers and stream each buffer over a socket, keeping memory usage constant. The server similarly reads the incoming stream incrementally, avoiding full‑payload buffering.

Feign, as an HTTP client used in Spring Cloud, can upload files via multipart/form‑data. Various method signatures are shown (File, byte[], FormData, MultipartFile, POJO). However, Feign's FormEncoder ultimately writes the encoded data into a ByteArrayOutputStream , which again buffers the entire request in memory before sending, reproducing the same high‑memory problem on the client side.

In conclusion, Dubbo is designed for small RPC payloads (default limit 8 MB) and is not appropriate for large file uploads. When file transfer is required, it is better to let the client stream the file directly over HTTP (or use Feign with a streaming encoder) to save resources.

BackendRPCDubbofeignHTTPfile transfer
Java Architect Essentials
Written by

Java Architect Essentials

Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.