الانتقال إلى المحتوى
Software ArchitectureSystem Design· 7 دقائق للقراءة

A Network Call Is Not a Method Call: Assumptions That Break Distributed Systems

A remote call can succeed, fail, or leave you not knowing which. Latency adds up, failures multiply, and a timeout is not a no.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

Support forwards a complaint: a customer was charged twice for one order. The logs show that checkout's call to the payments service timed out, the page said "Payment failed, please try again", and she clicked again. Both charges went through. Before the team split out payments, that line was payments.Charge(order). Now it's an await on an HTTP call, and the code around it never changed, because it looked like the same call.

The common misconception

The belief: calling another service over HTTP is just like calling a method, only a little slower. You wrap it in an interface, inject it, await it, and handle exceptions the way you always do.

Smart developers believe it because the tooling makes it look true. A generated client gives you typed methods, an IPaymentsClient interface looks like any in-process service, and on a laptop the other service runs on localhost and answers in milliseconds, every time. Microsoft's microservices guide describes the trap: in a monolith, components call each other with method calls, and "A direct conversion from in-process method calls into RPC calls to services will cause a chatty and not efficient communication that won't perform well in distributed environments."

The idea is old, too. Around the turn of the century, distributed object middleware promised that you could call an object without caring whether it lived in your process or on another machine. Martin Fowler's verdict on it: "you can't encapsulate the remote/in-process distinction."

What actually happens

A remote call has a third outcome

Fowler spells out the difference: "An in-process function call is fast and always succeeds (in that any exceptions are due to the application, not due to the mere fact of making the call). Remote calls, however, are orders of magnitude slower, and there's always a chance that the call will fail due to a failure in the remote process or the connection."

The worst case isn't a clear failure. It's a timeout. When no response arrives, any of these may be true: the request never reached the server, the server did the work and the response was lost, or the server is still working. That's , and the caller can't tell which one happened. Treat "no answer" as "no" and you charge twice. Treat it as "yes" and you ship unpaid orders.

Latency adds up

A method call costs nanoseconds, so nobody counts them. A remote call costs a network round trip plus serialization, and APIs designed for in-process use make many small calls. Fowler's example: in process, you can happily ask for 100 product prices with 100 calls; remotely, "you're usually better off to batch all that into a single call that asks for all 100 prices and availabilities in one go." The interface has to change shape, not just get slower.

Chains make it worse. Microsoft's guide: "The more you add synchronous dependencies between microservices, such as query requests, the worse the overall response time gets for the client apps."

Failures multiply along a chain

If serving a request needs three other services to answer synchronously, it fails whenever any of them is down or slow. Microsoft is direct: if one microservice must call others to answer a client, "you have an architecture that won't be resilient when some microservices fail." Slow is often worse than down, because waiting holds resources: "Timeouts that are too long cause threads and connections to accumulate during outages."

The eight fallacies

Peter Deutsch's list, as James Gosling's site publishes it, begins: "Essentially everyone, when they first build a distributed application, makes the following eight assumptions. All prove to be false in the long run and all cause big trouble and painful learning experiences." The :

  • The network is reliable
  • Latency is zero
  • Bandwidth is infinite
  • The network is secure
  • Topology doesn't change
  • There is one administrator
  • Transport cost is zero
  • The network is homogeneous

Fowler calls this list "the classic statement of why one should beware of any notion that distribution can be done transparently (or easily)." The double charge above breaks the first two at once.

The fix: design for three outcomes

C# Checkout.cs
public sealed class Checkout(HttpClient http){    public async Task<bool> PayAsync(Charge charge)    {        try        {            var response = await http.PostAsJsonAsync("/charges", charge);            return response.IsSuccessStatusCode;        }        catch (Exception)        {            return false; // timed out... but the card may have been charged        }    }}// The page says "Payment failed, try again",// and the second click charges the card again

The fixed version admits what the network can't promise. The call has a deadline, so a slow payments service can't hold the request forever. A 4xx means Payments answered and didn't charge. A 5xx or no answer means "unknown", and checkout shows "We're confirming your payment" instead of "try again". Because the caller creates the charge's Id, the unknown case can be resolved by asking Payments about it instead of charging again. Retrying is one possible next step, with risks covered later in this path; how to hold the HttpClient itself is covered in the article on IHttpClientFactory.

Method callNetwork call
OutcomesReturns or throwsSucceeds, fails, or unknown
CostToo small to countA round trip, every time
Good API shapeFine-grained, many callsCoarse-grained, few calls
FailureA bug in the codeRoutine: crashes, timeouts, deploys
Calling twiceUsually harmlessMay repeat the effect

How to apply it in your project

  1. Find the calls that cross the networkSearch for HttpClient, gRPC clients and generated API clients, including the ones hidden behind interfaces like IPaymentsClient. List every call a request makes.
  2. Give each one a deadlineSet a timeout per call that fits the end-to-end time the caller allows, and pass the request's cancellation token along.
  3. Decide what "unknown" means for each writeFor every call that changes something, write down what happens when there's no answer: check status by ID, show a pending state, or reconcile later.
  4. Make chatty calls coarseReplace loops of small remote calls with one call that sends or returns the whole set, and question every synchronous chain longer than one hop.

Key takeaways

  • A network call can succeed, fail, or leave you not knowing; design every remote call for all three.
  • A timeout doesn't mean the work didn't happen, so don't treat "no answer" as "no".
  • Remote calls cost a round trip each, so APIs must be coarse-grained, not chatty.
  • Synchronous chains add up latency and multiply the chance that something on the path fails.
  • The eight fallacies are a checklist of what the network won't do for you; check your design against them.

📚 المصادر

  1. The Eight Fallacies of Distributed Computing — Peter Deutsch, on James Gosling's site
  2. SE Radio 470: L. Peter Deutsch on the Fallacies of Distributed Computing (2021)
  3. Microservices and the First Law of Distributed Objects — Martin Fowler (2014)
  4. Communication in a microservice architecture — .NET Microservices e-book, Microsoft Learn
  5. Transient fault handling — Azure Architecture Center, Microsoft Learn

التعليقات (0)