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

📚 Interview question

What is Dapr? Explain its building blocks (service invocation, state, pub/sub, bindings, workflow), how the sidecar model works, and when it actually helps a .NET team rather than just adding another moving part.

Covers Dapr as a portable runtime: the daprd sidecar and its HTTP/gRPC API, the main building blocks, components that swap the backing service by YAML, the .NET SDK (Dapr.Client, Dapr.AspNetCore, Dapr.Workflow), Dapr on Azure Container Apps and AKS, and when to choose it over plain Azure SDKs.

Intermediate Theory Intermediate azure-container-apps cloud-native dapr microservices pub-sub sidecar

🎯 Key points

  • Dapr = CNCF graduated runtime; each app gets a daprd sidecar exposing building blocks over HTTP (default 3500) and gRPC (default 50001), ports configurable
  • Building blocks: service invocation, state management, pub/sub, bindings, actors, secrets, configuration, workflow
  • Components (YAML) bind a building block to a backend (Redis, Service Bus, Cosmos DB) so the app code does not change
  • Service invocation adds mTLS between sidecars, retries via resiliency policies and W3C trace propagation
  • .NET SDK: DaprClient, AddDapr/MapSubscribeHandler/[Topic] in ASP.NET Core, Dapr.Workflow (marked stable in the 1.16 release, September 2025)
  • Built into Azure Container Apps (managed sidecar); on AKS via the Dapr extension or Helm
  • Costs: extra hop (~1-2 ms), lowest-common-denominator APIs that hide broker-specific features, another runtime to upgrade and debug
  • Fits polyglot or multi-cloud teams; a single-cloud .NET team often does better with the Azure SDKs plus Aspire

⏱ 30-second answer

Dapr (Distributed Application Runtime) is a CNCF graduated project that runs a sidecar (daprd) next to each service. Your app calls the sidecar over local HTTP or gRPC, and the sidecar provides building blocks: service invocation, state, pub/sub, input/output bindings, secrets, actors and workflow. Which backing service is used, say Redis or Azure Service Bus for pub/sub, is chosen by a component YAML file, not by your code.

  • In .NET you use DaprClient, plus AddDapr() and [Topic] subscriptions in ASP.NET Core.
  • Azure Container Apps runs the sidecar for you; on AKS you install the Dapr extension.

It helps polyglot or multi-cloud teams and teams that want actors or workflow without building them. The trade-off: an extra network hop, simpler but narrower APIs than the native SDKs, and one more runtime to operate.

🗣 Full answer (senior)

How I would answer this in an interview

"Dapr is a runtime that sits next to my service as a sidecar process, daprd, and gives me distributed-systems capabilities through a local API. Instead of my code taking a dependency on the Service Bus SDK, it posts to localhost:3500/v1.0/publish/pubsub/orders, and a component file says that pubsub is Azure Service Bus in production and Redis on my laptop. The same pattern covers service invocation, state stores, bindings to things like queues and cron, secrets, the actor model and durable workflows.

In .NET the SDK makes it feel native: DaprClient for publishing, state and invocation, AddDapr() and MapSubscribeHandler() so ASP.NET Core endpoints marked with [Topic("pubsub", "orders")] receive events, and Dapr.Workflow, which became stable in the 1.16 release, for long-running orchestrations. On Azure Container Apps I just enable Dapr on the app and declare components on the environment; on AKS there is a managed Dapr extension. Service invocation between sidecars is mTLS-encrypted and propagates trace context automatically, and resiliency policies give me retries, timeouts and circuit breakers in YAML.

The mistake I see is adopting Dapr because it sounds cloud-native, when the team is all .NET on Azure and never going to swap Service Bus for Kafka. Then you pay for an extra hop, lose features the native SDK has, like sessions or scheduled messages in some cases, and you have one more runtime to upgrade. I reach for Dapr when portability, polyglot services or actors and workflow are real requirements, not as a default."


Building blocks at a glance

Building block What it gives you Typical backing components
Service invocation Name-based calls, mTLS, retries, tracing Sidecar to sidecar (gRPC)
Pub/sub Publish and subscribe with CloudEvents envelopes, at-least-once Azure Service Bus, Kafka, RabbitMQ, Redis Streams
State management Key/value with ETags (optimistic concurrency), transactions Redis, Cosmos DB, SQL Server, PostgreSQL
Bindings Trigger on or write to external systems Storage queues, cron, SMTP, Event Hubs
Secrets Read secrets through one API Key Vault, Kubernetes secrets
Actors Virtual actors with turn-based concurrency and timers A state store that supports actors
Workflow Durable, replayed orchestrations in code Uses the actor/state infrastructure

When it fits and when it does not

Fits Does not fit
Polyglot services (.NET, Go, Python) that need the same messaging and state semantics A small all-.NET team on one cloud
Real multi-cloud or on-premises plus cloud requirement You need advanced broker features the abstraction hides
You want actors or durable workflow without Orleans or Durable Functions Latency-critical hot paths where 1-2 ms per hop matters
Already on Azure Container Apps where Dapr is a toggle No one on the team wants to own another runtime's upgrades

Production example

A team running [six] services on Azure Container Apps used Dapr pub/sub over Service Bus and state over Redis. Local development used the same components pointed at Redis, so new starters ran the whole system with dapr run and no cloud access. The sidecar added roughly [1-2 ms] per call at p50, which was acceptable against a 200 ms API budget.

🔍 What the interviewer is checking

Checks whether the candidate understands what Dapr actually does mechanically and can judge when its abstraction is worth the cost.

Green flags

  • Explains the sidecar, the local API and components clearly
  • Knows pub/sub is at least once and handlers must be idempotent
  • Mentions Azure Container Apps' built-in Dapr and the .NET SDK pieces
  • Weighs portability against latency, lost features and operational load

Red flags

  • Thinks Dapr is a message broker or a service mesh replacement in every case
  • Claims component swaps keep identical guarantees
  • Recommends it everywhere without a reason

📚 Learn in depth

1. The sidecar model

+-------------------- pod / container app --------------------+
|                                                             |
|  orders-api (.NET)  --HTTP/gRPC localhost-->  daprd sidecar  |----> Service Bus (pubsub component)
|        ^                                       |    |        |----> Redis (statestore component)
|        |  subscription callback (POST /orders) |    |        |
|        +---------------------------------------+    +--mTLS--> other daprd --> pricing-api
+-------------------------------------------------------------+

The app never holds broker credentials: the sidecar reads the component definition (with secrets from a secret store or managed identity) and talks to the backend. The app talks to the sidecar on ports 3500 (HTTP) and 50001 (gRPC). In Kubernetes the Dapr sidecar injector adds the container to pods annotated dapr.io/enabled: "true"; the control plane (operator, placement, sentry for certificates, scheduler) runs in dapr-system.

2. Components and portability

A component is a CRD (or a YAML file in self-hosted mode):

kind: Component
metadata: { name: pubsub }
spec:
  type: pubsub.azure.servicebus.topics
  metadata: [ { name: namespaceName, value: sb-prod.servicebus.windows.net } ]

Swapping to pubsub.redis changes behaviour without a code change, but semantics differ: ordering, maximum message size, dead-lettering and delivery guarantees are the broker's, not Dapr's. Portability is of the API, not of guarantees.

3. Pub/sub mechanics

Dapr wraps payloads in CloudEvents 1.0. On start-up the sidecar calls GET /dapr/subscribe on your app (generated by MapSubscribeHandler() from [Topic] attributes) and then POSTs each message to the matching endpoint. Your response decides the outcome: 2xx = success, RETRY status or 5xx = redeliver, DROP = discard (to a dead-letter topic if configured). Delivery is at least once, so handlers must be idempotent.

4. Service invocation and resiliency

DaprClient.InvokeMethodAsync or an HttpClient from DaprClient.CreateInvokeHttpClient("pricing") goes app -> local sidecar -> remote sidecar -> remote app. Sidecars authenticate each other with certificates issued by Sentry (mTLS) and add traceparent. A Resiliency resource defines timeouts, retries and circuit breakers per target. Do not also stack Polly retries on the same call, or retries multiply.

5. Workflow

Dapr.Workflow runs orchestrations as replayed code (like Durable Functions): the orchestrator must be deterministic, activities do the I/O. As of the 1.16 release (September 2025) the .NET workflow SDK was marked stable, and later releases continue on a roughly quarterly cadence; check the current supported versions before you pin one.

6. Costs

Cost Detail
Latency One or two extra local hops per call; low single-digit ms
Resources A sidecar per replica (tens of MB of memory)
Operations Control plane upgrades, certificate rotation, version skew between runtime and SDK
Debugging Failures can be in your app, the sidecar or the component; you need sidecar logs too

Try it yourself

  1. Install the Dapr CLI, run dapr init, and start an API with dapr run --app-id orders --app-port 5000 -- dotnet run.
  2. Publish an event with DaprClient.PublishEventAsync and receive it in a [Topic] endpoint; return 500 and watch redelivery.
  3. Swap the pub/sub component from Redis to another broker and confirm no code changes.
  4. Measure p50/p99 of a direct HttpClient call versus Dapr service invocation with a small load test.
  5. Enable Dapr on an Azure Container App and inspect the component on the environment.

💻 Code

A minimal .NET 10 API that publishes and subscribes through Dapr, plus the component that binds pubsub to Azure Service Bus.

// Program.cs (orders-api)
using Dapr;
using Dapr.Client;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDaprClient();          // DaprClient talks to the local sidecar

var app = builder.Build();
app.UseCloudEvents();                       // unwraps the CloudEvents envelope
app.MapSubscribeHandler();                  // serves GET /dapr/subscribe from [Topic] metadata

app.MapPost("/orders", async (PlaceOrder cmd, DaprClient dapr, CancellationToken ct) =>
{
    var evt = new OrderPlaced(Guid.NewGuid(), cmd.Sku, cmd.Quantity);
    // No Service Bus SDK here: the component decides the broker.
    await dapr.PublishEventAsync("pubsub", "orders", evt, ct);
    return Results.Accepted($"/orders/{evt.OrderId}", evt);
});

// The sidecar POSTs each message here; a non-2xx response causes redelivery.
app.MapPost("/handlers/order-placed", [Topic("pubsub", "orders")] async (
    OrderPlaced evt, DaprClient dapr, CancellationToken ct) =>
{
    // Idempotency: at-least-once delivery, so skip events already handled.
    var key = $"processed-{evt.OrderId}";
    if (await dapr.GetStateAsync<bool>("statestore", key, cancellationToken: ct)) return Results.Ok();

    // ... do the work ...
    await dapr.SaveStateAsync("statestore", key, true, cancellationToken: ct);
    return Results.Ok();
});

app.Run();

public sealed record PlaceOrder(string Sku, int Quantity);
public sealed record OrderPlaced(Guid OrderId, string Sku, int Quantity);
# components/pubsub.yaml - swap type to pubsub.redis for local development
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: pubsub
spec:
  type: pubsub.azure.servicebus.topics
  version: v1
  metadata:
    - name: namespaceName
      value: sb-orders-prod.servicebus.windows.net
    - name: azureClientId          # user-assigned managed identity, no connection string
      value: 00000000-0000-0000-0000-000000000000
dapr run --app-id orders-api --app-port 5080 --resources-path ./components -- dotnet run

⚠ Common mistakes

  • Mistake: Adopting Dapr "for portability" on a single-cloud, single-language platform. Why it is wrong: You pay the hop, the runtime and the narrower API for a swap you will never make. Instead: Use the native Azure SDKs (with Aspire integrations) unless portability or polyglot needs are real.
  • Mistake: Assuming swapping components keeps the same guarantees. Why it is wrong: Ordering, message size limits and dead-lettering come from the broker, not from Dapr. Instead: Test against the production component and document the semantics you rely on.
  • Mistake: Writing non-idempotent subscription handlers. Why it is wrong: Pub/sub is at least once; retries and redelivery cause duplicate side effects. Instead: De-duplicate by event id or make the operation naturally idempotent.
  • Mistake: Stacking Polly retries on top of Dapr resiliency policies. Why it is wrong: Retries multiply and hammer a failing service. Instead: Choose one layer for retries, usually the Dapr resiliency policy when calls go through the sidecar.
  • Mistake: Putting connection strings in component files committed to git. Why it is wrong: Secrets leak, and rotation means redeploying. Instead: Use managed identity in the component or a secretKeyRef to a secret store such as Key Vault.
  • Mistake: Ignoring the sidecar when debugging. Why it is wrong: Many failures (component init, mTLS, subscription registration) only appear in daprd logs. Instead: Check sidecar logs and the Dapr dashboard first when messages do not arrive.
  • Mistake: Letting the Dapr runtime and SDK versions drift. Why it is wrong: Unsupported combinations and breaking changes (for example dropped .NET versions) bite at upgrade time. Instead: Upgrade runtime and SDK together within the supported window.

🏛 Senior insight: trade-offs

Dapr is an abstraction trade: you exchange the depth of each vendor SDK for one consistent API across languages and backends, plus free mTLS, tracing and resiliency between services. That trade pays off when the organisation is polyglot, runs in more than one environment, or wants actors and workflow as a platform capability. For an all-.NET Azure shop, the equivalent is usually Azure SDKs + Aspire for local orchestration + the standard resilience handler, with fewer moving parts.

What you give up is concrete. Through the generic pub/sub API you lose or must reach through metadata for Service Bus features such as sessions for ordered processing, scheduled enqueue time, deferral and fine-grained dead-letter handling; through the state API you lose Cosmos DB's rich queries and change feed; and the sidecar adds roughly a millisecond or two per hop and tens of MB per replica. Where it shines: a [logistics or IoT] platform with Go, Python and .NET services sharing one messaging model, an ISV that must deploy to customers' AKS, EKS or on-premises clusters, or a team that needs durable workflows or virtual actors without adopting Orleans or Durable Functions. Where it hurts: latency-sensitive trading or payments hot paths, and small teams who would rather debug one SDK than an app, a sidecar and a component.

Option When it fits Cost When not to
Dapr Polyglot, multi-cloud, Container Apps already Sidecar hop, runtime upgrades, narrower APIs Single-language single-cloud team
Native Azure SDKs + Aspire All-.NET on Azure Vendor-specific code, more wiring per service You must run on several clouds
MassTransit / NServiceBus Rich messaging patterns (sagas, outbox) in .NET Library learning curve, commercial licence for some You need cross-language semantics

How to assess it: run a two-week spike on one service, then compare p99 latency with and without the sidecar under realistic load, count infrastructure code removed, list the broker features you had to give up, and ask the on-call engineers how long it took them to diagnose a deliberately broken component. Pin and upgrade runtime and SDK versions together within Dapr's supported window.

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions Dapr service invocation or pub/sub Why: Checks they can still choose between HTTP, gRPC and messaging when Dapr is not in the picture.
    How to answer

    There are three styles. HTTP/JSON is universal and easy to debug; in .NET use IHttpClientFactory with AddStandardResilienceHandler for timeouts, retries and a circuit breaker. gRPC gives strict Protobuf contracts, smaller payloads, streaming and deadlines over HTTP/2, which suits high-volume internal calls, but needs layer 7 load balancing. Messaging (Azure Service Bus) removes temporal coupling: the receiver can be down or slow and the work still completes, at the cost of eventual consistency and idempotent consumers.

    I choose per interaction: if the caller needs an answer to continue, call synchronously; if it is a command or an event that can finish later, send a message. For security, each service authenticates with managed identity to get an Entra ID token the callee validates, and mTLS from a mesh or platform encrypts the hop. The trade-off: every synchronous hop multiplies latency and failure.

  2. When: Candidate mentions topics and subscriptions Why: Checks they understand queues, topics and competing consumers behind Dapr pub/sub.
    How to answer

    A queue is point-to-point: a producer sends a message and exactly one consumer processes it. A topic is publish/subscribe: each subscription gets its own copy, so billing, email and analytics can all react to one OrderPlaced event.

    • Competing consumers: run several instances on one queue (or one subscription) and the broker hands each message to one of them, so you scale out and survive a crashed instance.
    • A broker decouples services in time (the consumer can be down), location (the producer doesn't know who listens) and load (the queue absorbs spikes).
    • Delivery is normally at-least-once, so consumers must tolerate duplicates.

    The trade-off: you lose the immediate answer. If the caller needs the result to continue, a direct HTTP call is simpler.

  3. When: Candidate mentions swapping backends locally Why: Checks they can compare Dapr components with Aspire hosting and client integrations.
    How to answer

    Integrations come in two halves:

    • Hosting integrations (Aspire.Hosting.*, in the AppHost) model a resource: run SQL Server or Redis as a container, or generate Bicep for an Azure resource such as Service Bus or Storage.
    • Client integrations (Aspire.*, in the service) register the SDK client in DI from a named connection string, plus health checks, OpenTelemetry and retries.

    For Azure, AddAzureServiceBus("messaging") either runs an emulator locally (RunAsEmulator()), provisions a real resource in your subscription during aspire run, or points at an existing one. Deployed apps connect with managed identity. ConfigureInfrastructure lets you change the generated Bicep.

    The trade-off: consistent, observable clients with very little code, versus an extra package layer whose defaults you must know and keep up to date.

🛠 Real-world problems: how you handle them

Events silently not delivered after moving pub/sub to Dapr
Situation
A team moved [four] .NET services on Azure Container Apps from the Service Bus SDK to Dapr pub/sub to share one messaging approach with a [Python] service.
Signals
Orders were accepted (202) but fulfilment never received them; the Service Bus topic showed messages arriving and the subscription growing; no errors in the fulfilment app logs.
Investigation
Checked the Dapr sidecar logs in Container Apps (system logs) and found no subscriptions registered for fulfilment. `GET /dapr/subscribe` returned an empty list because `MapSubscribeHandler()` was missing, and the component was scoped to other app ids only.
Resolution
Immediate: added `MapSubscribeHandler()` and `UseCloudEvents()`, and added the fulfilment app id to the component's scopes; the backlog drained in [minutes]. Real fix: an integration test that starts the app with `dapr run` and asserts the subscription list.
Prevention
A smoke test in the pipeline that publishes a test event and asserts receipt, an alert on Service Bus subscription active message count, and a service template with the Dapr wiring already in place.

How to tell it (STAR)

**S:** We had moved [four] services to Dapr pub/sub, and after one release fulfilment stopped receiving orders without a single error. **T:** I was asked to find why messages piled up on the topic. **A:** I went to the sidecar logs rather than the app logs and saw that fulfilment had registered no subscriptions: the subscribe endpoint was missing and the component was scoped to the wrong apps. I fixed both, then added a pipeline smoke test that publishes and asserts receipt, and an alert on subscription backlog. **R:** The [12,000]-message backlog drained in [20 minutes], and we have had [no] silent delivery failures since.

↩ Usually asked after

More in Optional Advanced Tools

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me