📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š Interview question

Your team is moving a feature out of the monolith into its own microservice. What actually changes for you as a developer when a method call becomes a network call to another service, and what costs do you take on compared with keeping it in the monolith?

What a microservice is in practice, and the concrete costs of turning in-process calls into network calls: latency, partial failure, no shared transaction, versioning, deployment and observability.

Junior Theory Beginner distributed-systems httpclient latency microservices monolith partial-failure

🎯 Key points

  • A microservice is independently deployable, owns its data and one business capability; size is not the point
  • An in-process call takes nanoseconds; a network call adds roughly 1–5 ms in-region (more with TLS, serialisation, proxies or cross-region hops) and can fail or time out
  • Partial failure: a timeout means unknown outcome, so retries need idempotency
  • No shared database transaction across services: eventual consistency, sagas or outbox instead
  • The contract becomes public: versioning and backward compatibility on every change
  • Operational costs per service: pipelines, service discovery, health checks, dashboards, alerts and on-call
  • Observability becomes mandatory: distributed tracing and correlated logs (OpenTelemetry, Application Insights)
  • Benefits only pay off with independent teams, deploy cadence or scaling needs

⏱ 30-second answer

A microservice is a small, independently deployable service that owns one business capability and its data. When a method call becomes a network call, four things change: it is ~1,000Γ— slower (milliseconds, not nanoseconds), it can fail partially (a timeout tells you nothing about whether the work happened), there is no shared transaction with your data, and the method signature becomes a public contract you must version. On top of that you take on pipelines, tracing, service discovery and on-call per service. The trade-off: you buy independent deployment and team autonomy and pay for it with distributed systems complexity, so it is only worth it when those benefits are real.

πŸ—£ Full answer (senior)

How I would answer this in an interview

"A microservice is a service that owns one business capability and its own data, and that a team can deploy without coordinating with anyone else. The moment I move code out of the monolith, a method call like _pricing.GetPrice(sku) becomes an HttpClient or gRPC call, and that changes four things for me as a developer.

First, latency: an in-process call is nanoseconds, a call inside one Azure region is one to five milliseconds, so a loop that called the method 200 times now costs a second. Second, partial failure: the call can time out, and a timeout doesn't tell me whether the other side did the work, so I need timeouts, bounded retries and idempotency. Third, I lose the shared database transaction: if I save an order and the pricing service records a reservation, those can no longer commit together, so I need eventual consistency, the outbox pattern or a saga. Fourth, the signature is now a public contract: I can't rename a field and fix all callers in one commit, because other teams deploy on their own schedule.

The mistake I see is teams splitting code into services but keeping the habits of a monolith: chatty calls, a shared database, and deploying everything together. Then you pay all the costs and get none of the benefits. My one-line summary: a microservice turns a compile-time dependency into a runtime dependency, and you should only make that trade when independent deployment is worth more than the complexity."


What changes, side by side

Concern Method call in the monolith Call to another service
Latency ~1–50 ns ~1–5 ms in-region, 10–30 ms cross-region (Australia East ↔ Southeast)
Failure Exception, or it worked Exception, timeout (unknown outcome), slow response, wrong version
Transactions One DbContext.SaveChanges No shared transaction: outbox, saga, compensation
Contract change Rename, compiler fixes callers Versioning, tolerant readers, deprecation period
Debugging One stack trace Distributed trace across processes (OpenTelemetry, Application Insights)
Deployment One pipeline One pipeline per service, plus compatibility between versions
Security In-process Service-to-service auth (managed identity, mTLS)

What you gain

Benefit Real only when…
Independent deployment Teams actually release on different cadences
Independent scaling One part has very different load (e.g. search vs admin)
Fault isolation Calls are asynchronous or have fallbacks; a sync chain fails together
Technology freedom You accept the cost of supporting several stacks
Team autonomy Each service has one owning team

When not to split

  • One team owns everything and releases together anyway.
  • The boundary isn't stable yet (new product, domain still being discovered).
  • The two parts change together in most pull requests.

In those cases a modular monolith gives you the boundaries without the network.

Production example

A checkout page that called a pricing module 40 times per basket in-process (~0.2 ms total) went to ~180 ms p95 after pricing became a separate service, because each call was a 4–5 ms round trip. Replacing the loop with one batch endpoint (POST /prices:batch) brought it back to ~12 ms, and adding a 2-second timeout with a cached fallback stopped pricing outages taking checkout down.

πŸ” What the interviewer is checking

Checks that the candidate understands microservices as a trade-off with concrete costs, not as a default good.

Green flags

  • Names latency, partial failure, loss of transactions and contract versioning
  • Gives numbers (nanoseconds vs milliseconds)
  • Mentions owning data and independent deployment as the defining traits
  • Knows when a modular monolith is the better choice

Red flags

  • "Microservices are just small services" with no mention of data ownership
  • Assumes the network is reliable or fast
  • Thinks a shared database is fine

πŸ“š Learn in depth

1. What a microservice really is

The definition that matters in interviews has three parts:

  1. Independently deployable: you can release it without releasing anything else.
  2. Owns its data: no other service reads or writes its tables.
  3. Built around a business capability (Orders, Pricing, Payments), not a technical layer ("the database service").

Size is not the point. A service with 50,000 lines that one team owns and deploys alone is a fine microservice.

2. From call stack to network

Monolith                         Microservices
--------                         -------------
CheckoutController               Checkout service
   |  GetPrice(sku)  ~20 ns         |  HTTP GET /prices/{sku}
   v                                |  DNS -> TCP/TLS (pooled) -> serialise
PricingService                      v        ~1-5 ms, may time out
   |                             Pricing service
   v                                |
Same DbContext / transaction        v
                                 Its own database

Every arrow on the right can fail independently: DNS, the connection, the other process, its database, or the reply on the way back.

3. Partial failure in one picture

Checkout                 Pricing
   | --- reserve(sku) ---> |
   |                       | writes reservation, commits
   |      X reply lost     |
   | (timeout after 2 s)   |
   | Did it work? Unknown.

So the caller must either retry with an idempotency key the callee de-duplicates on, or query the outcome. This is the single biggest mindset change.

4. Losing the transaction

In the monolith, SaveChangesAsync commits the order and the reservation atomically. Across services there is no shared transaction (distributed two-phase commit is avoided in the cloud). Typical replacements:

  • Outbox: write the order and an OrderPlaced message in one local transaction, publish later.
  • Saga: a sequence of local transactions with compensating actions.
  • Accept eventual consistency and design the UI for "pending".

5. The contract becomes public

Once another team calls you, every response field is a promise. Rules that follow:

  • Add fields, never rename or remove without a deprecation period.
  • Consumers ignore unknown fields (tolerant reader).
  • Contract tests catch breaking changes before deployment.

6. The operational bill

Per service you now need: a pipeline, container image, configuration and secrets, health checks, dashboards, alerts, an on-call owner, and distributed tracing so a request can be followed across services. .NET helps with Microsoft.Extensions.Http.Resilience (timeouts, retries, circuit breakers), Microsoft.Extensions.ServiceDiscovery and OpenTelemetry, but the work doesn't disappear.

Try it yourself

  1. Write a BenchmarkDotNet test comparing an in-process method call with an HttpClient call to a local Minimal API. Note the ratio.
  2. Add await Task.Delay(3000) in the callee and a 1-second HttpClient.Timeout in the caller. Check whether the callee still finished its work.
  3. Add OpenTelemetry to both apps and view the trace in the Aspire dashboard or Jaeger.
  4. Turn a loop of 50 single calls into one batch call and measure the difference.

πŸ’» Code

The same price lookup, before and after the split. Note what the remote version has to add.

namespace Checkout;

// Before: in-process. Fast, atomic, compiler-checked.
public interface IPricing
{
    decimal GetPrice(string sku);
}

// After: a remote call. Everything below exists only because of the network.
public sealed record PriceDto(string Sku, decimal Amount, string Currency);

public sealed class PricingClient(HttpClient http)
{
    public async Task<IReadOnlyList<PriceDto>> GetPricesAsync(
        IReadOnlyCollection<string> skus, CancellationToken ct)
    {
        // One batch call instead of N single calls: each round trip costs milliseconds.
        using var response = await http.PostAsJsonAsync("/prices:batch", skus, ct);
        response.EnsureSuccessStatusCode();
        return await response.Content.ReadFromJsonAsync<List<PriceDto>>(ct) ?? [];
    }
}
// Program.cs: timeouts, retries and circuit breaker come from Microsoft.Extensions.Http.Resilience,
// and the base address comes from service discovery instead of a hard-coded URL.
builder.Services.AddServiceDiscovery();
builder.Services.AddHttpClient<PricingClient>(c => c.BaseAddress = new Uri("https+http://pricing"))
    .AddServiceDiscovery()
    .AddStandardResilienceHandler(); // total timeout, retry with jitter, circuit breaker

⚠ Common mistakes

  • Mistake: Splitting services by technical layer ("data service", "validation service"). Why it is wrong: every feature then needs changes and calls across several services. Instead: split by business capability with its own data.
  • Mistake: Keeping the chatty call pattern from the monolith. Why it is wrong: 50 calls Γ— 4 ms is 200 ms of pure network time. Instead: batch endpoints, or move the data closer.
  • Mistake: Treating a timeout as "it failed" and retrying a payment blindly. Why it is wrong: the first call may have succeeded, so the customer is charged twice. Instead: idempotency keys or an outcome query.
  • Mistake: Sharing one database between the new service and the monolith. Why it is wrong: schema changes still need coordinated releases, so you gain nothing. Instead: the service owns its tables; others use its API or events.
  • Mistake: No timeout on HttpClient calls beyond the 100-second default. Why it is wrong: a slow dependency ties up requests and threads. Instead: explicit timeouts via the resilience handler.
  • Mistake: Splitting before the domain is understood, or adopting microservices because they are fashionable. Why it is wrong: wrong boundaries are much more expensive to move across a network, and a small team pays the full operational cost for no autonomy gain. Instead: start as a modular monolith and extract stable modules when a team, scaling or release-cadence need appears.
  • Mistake: Shipping the first service without distributed tracing or correlated logs. Why it is wrong: an error that crosses two processes can't be followed, and incidents take hours. Instead: OpenTelemetry tracing and a shared correlation id from day one, with per-service dashboards and alerts.

πŸ› Senior insight: trade-offs

The honest framing is that microservices are an organisational tool more than a technical one: they let several teams deploy independently. If you have one team, you mostly get the costs. A strong candidate states the price in concrete terms (latency per hop, unknown outcomes, no shared transaction, contract versioning) and names the cheaper alternative.

Option When it fits Cost When not to
Monolith One team, early product Coupled releases as it grows Many teams blocking each other
Modular monolith Clear modules, 1–4 teams Discipline to keep boundaries Parts need very different scaling or release cadence
Microservices Several teams, stable boundaries, platform support Network, ops, consistency, versioning Boundaries unclear, no platform or observability

Measure before and after: deployment frequency per team, lead time, p95 latency of user journeys, and change failure rate.

πŸ”— Follow-ups the interviewer may ask

  1. When: Candidate mentions timeouts or partial failure Why: Checks they can reason about an unknown outcome and what the calling code must do.
    How to answer

    Partial failure means part of a distributed system fails while the rest keeps running, and no single node can see the whole picture. The sharpest example is a timeout: when your call to the payments service times out, the request might have been lost, the service might have crashed before or after charging the card, the response might have been lost, or it might still be running. A timeout means the outcome is unknown, not that it failed. So calling code must be written for the unknown: make the operation idempotent (or send an idempotency key) so a retry can't do the work twice, or look up the outcome by a client-generated id before retrying, and run reconciliation for anything left in doubt. The trade-off is extra design work on every write that crosses the network.

  2. When: Candidate says a modular monolith might be better Why: Checks they can describe the alternative and how boundaries are enforced without a network.
    How to answer

    A modular monolith is one deployable split into modules aligned to business capabilities β€” Orders, Billing, Catalogue β€” each with hard boundaries.

    • Each module owns its data: its own schema and DbContext, no cross-module joins or foreign keys.
    • Modules talk only through a public contract (an interface and DTOs) or integration events; everything else is internal.
    • Boundaries are enforced: separate projects, internal types, architecture tests, even per-schema database permissions.

    You get microservice-style boundaries with monolith-style operations: one pipeline, in-process calls, easy refactoring. The trade-off: one runtime, one release and one scaling unit, and it only works if the boundaries are enforced β€” otherwise it decays into a big ball of mud.

  3. When: Candidate talks about benefits and costs in general terms Why: Checks deeper understanding of the distributed systems tax and organisational fit.
    How to answer

    Microservices are small, independently deployable services, each owning one business capability and its own data, talking over the network via APIs or messages.

    • Benefits: independent deployment and scaling, team autonomy, fault isolation, technology choice per service.
    • The distributed systems tax: network latency and partial failure, eventual consistency and sagas instead of transactions, versioned contracts, distributed tracing, and many pipelines and on-call rotations.
    • They mainly solve an organisational problem: many teams needing to release without coordinating (Conway's law).

    They fit when you have several teams, stable boundaries and mature DevOps. Otherwise a modular monolith gives most of the benefits for a fraction of the cost. The worst outcome is a distributed monolith: all the cost, none of the independence.

More in Microservices

Last updated 23 Nov 2026.

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me