Skip to main content

๐ŸŒŸ Dot net Microservices interview questions

Here is a comprehensive list of 200 .NET microservices coding questions covering all core microservices concepts and cross-cutting concerns relevant for designing, building, deploying, and maintaining .NET-based distributed systems.


๐Ÿงฉ A. Microservices Fundamentals (20)

  1. Build a microservice in .NET 8 that exposes a simple CRUD API.
  2. Implement communication between two microservices using REST.
  3. How would you design microservices for an e-commerce application?
  4. Create a microservice that handles user registration and login.
  5. How do you isolate domain logic in a microservice?
  6. How to apply the "Single Responsibility Principle" in microservices?
  7. Design a service registry/discovery mechanism using custom middleware.
  8. Implement a service that handles file uploads and metadata separately.
  9. Build a stateless microservice and explain its benefits.
  10. Implement health check endpoints in .NET 8.
  11. Demonstrate versioning in a microservice API.
  12. Add Swagger/OpenAPI support to your microservices.
  13. Create a microservice that exposes gRPC endpoints.
  14. How do you secure gRPC between microservices?
  15. Design a microservice architecture for a banking system.
  16. Create a .NET microservice that uses hosted services.
  17. Build a modular monolith and later split into microservices.
  18. Demonstrate backward compatibility in microservice updates.
  19. Implement graceful shutdown in your .NET service.
  20. Implement async programming pattern in your microservice.

๐Ÿ”„ B. Inter-Service Communication (20)

  1. Implement synchronous REST communication between services.
  2. Implement asynchronous communication using RabbitMQ.
  3. Set up Kafka and publish events from a .NET microservice.
  4. Use MassTransit to connect services using RabbitMQ.
  5. Design an event-driven architecture using Azure Service Bus.
  6. How to implement request-response with message queues?
  7. Implement the Outbox pattern in a .NET microservice.
  8. Demonstrate retry mechanism in HTTP communication.
  9. Build a messaging service that communicates with multiple consumers.
  10. Handle message duplication in event-driven microservices.
  11. How do you deal with transactional messages?
  12. Implement correlation IDs for distributed tracing.
  13. Build a distributed caching mechanism with Redis between services.
  14. Create a message handler pipeline using MediatR.
  15. How to use gRPC for inter-service communication in .NET 8?
  16. Demonstrate fallback communication using Polly.
  17. Implement the Choreography pattern using events.
  18. Implement Saga Orchestration pattern in .NET microservices.
  19. Use SignalR for real-time communication between microservices.
  20. How would you achieve consistency across services in a distributed system?

⚙️ C. Domain-Driven Design (DDD) (20)

  1. Implement Aggregate Root in a service.
  2. Use Value Objects in a domain model.
  3. Split Entity vs Aggregate in a domain model.
  4. Build a bounded context and show integration points.
  5. Use domain events within a microservice.
  6. Implement a simple CQRS pattern using MediatR.
  7. Implement a complex CQRS pattern with separate read/write databases.
  8. Use Unit of Work and Repository pattern in a domain.
  9. How would you handle domain logic validation?
  10. Demonstrate Anti-Corruption Layer between services.
  11. Create a shared kernel in DDD.
  12. How do you separate application and domain layers?
  13. Use dependency injection in domain service.
  14. Create a layered architecture within a microservice.
  15. Demonstrate contract-first development.
  16. How do you evolve domain models without breaking consumers?
  17. What is an eventual consistency model, and how do you handle it in code?
  18. Demonstrate Aggregate consistency with distributed transactions.
  19. Implement Specification pattern in DDD.
  20. Create a service that uses multiple bounded contexts.

๐Ÿ”’ D. Security & Authentication (20)

  1. Implement OAuth 2.0 in a microservice.
  2. Set up IdentityServer with multiple services.
  3. Use JWT tokens for authentication between microservices.
  4. Secure REST APIs using custom middleware.
  5. Implement token validation in a gRPC microservice.
  6. Create a shared authentication service.
  7. Implement role-based access in a service.
  8. Use API gateway for authentication enforcement.
  9. Demonstrate how to use Azure AD in .NET microservices.
  10. Implement certificate-based authentication.
  11. Apply CORS policy in an API.
  12. Demonstrate rate limiting using ASP.NET Core middleware.
  13. Log and audit authentication failures.
  14. Implement refresh tokens using IdentityServer.
  15. Use Keycloak with .NET microservices.
  16. Secure secrets using Azure Key Vault.
  17. Implement IP whitelisting in .NET APIs.
  18. Demonstrate identity propagation across services.
  19. Secure service-to-service communication using mTLS.
  20. Build a custom authorization attribute.

๐Ÿงฐ E. Cross-Cutting Concerns (40)

  1. Centralized logging using Serilog + Elasticsearch.
  2. Implement distributed tracing using OpenTelemetry.
  3. Set up Application Insights for all services.
  4. How to implement correlation ID in logs.
  5. Create a shared logging library.
  6. Add structured logging with contextual metadata.
  7. Monitor microservices using Prometheus and Grafana.
  8. Setup circuit breaker using Polly.
  9. Implement retry and fallback policies using Polly.
  10. Configure centralized configuration using Consul.
  11. Use Azure App Configuration across services.
  12. Create health and readiness probes.
  13. Setup metrics collection for service performance.
  14. Enable telemetry and alerts.
  15. Use FluentValidation for request models.
  16. Build a wrapper for database retry logic.
  17. Add request/response logging middleware.
  18. Add model state validation filters.
  19. Build a common exception handling middleware.
  20. Implement a custom caching layer.
  21. Setup Redis distributed caching.
  22. Use output caching in ASP.NET Core.
  23. Implement input sanitization middleware.
  24. Configure Caching headers.
  25. Build an audit logging module.
  26. Capture API usage metrics.
  27. Create a background worker for message processing.
  28. Store logs to Azure Blob Storage.
  29. Use AppSettings.json + secrets.json + environment variables securely.
  30. Store configs in Azure Key Vault.
  31. Create a global exception handler in .NET.
  32. How to implement centralized exception tracking.
  33. Enable detailed error logging per environment.
  34. Use middleware to detect and block DoS patterns.
  35. Capture user activity logs.
  36. Build a metrics dashboard from service logs.
  37. Implement a request throttling mechanism.
  38. Design log aggregation strategy.
  39. Design a metrics collection and alert system.
  40. Apply GDPR logging compliance.

๐Ÿงช F. Testing & Resiliency (20)

  1. Write unit tests for a controller.
  2. Write integration tests for a microservice.
  3. Mock external API using WireMock or MockServer.
  4. Use xUnit and Moq to test service logic.
  5. Write tests for MediatR handlers.
  6. Test database interactions with Testcontainers.
  7. Perform contract testing using Pact.
  8. Validate API response using snapshot testing.
  9. Write BDD tests using SpecFlow.
  10. Create smoke tests for microservices.
  11. Setup chaos testing in .NET.
  12. Build resilience test cases.
  13. Test service with disabled downstream services.
  14. Simulate service failure and verify circuit breaker.
  15. Validate retry mechanism with failed requests.
  16. Stress test using k6.
  17. Implement unit tests for Domain Events.
  18. Perform fault injection and analyze logs.
  19. Use mocking to test Saga workflows.
  20. Test gRPC contracts with Protobuf verifier.

๐Ÿš€ G. Deployment & CI/CD (20)

  1. Containerize a microservice with Docker.
  2. Write Dockerfile for multi-stage .NET builds.
  3. Create docker-compose for multi-service app.
  4. Setup Kubernetes deployment for microservices.
  5. Use Helm to manage .NET microservices.
  6. Implement blue-green deployment strategy.
  7. Setup GitHub Actions for build and deploy.
  8. Configure Azure DevOps pipeline for microservice app.
  9. Deploy to Azure App Service with staging slots.
  10. Use Terraform to provision cloud infra.
  11. Build a pipeline that runs unit and integration tests.
  12. Push container to Azure Container Registry.
  13. Automate health check validation post-deploy.
  14. Configure rolling deployment in AKS.
  15. Setup Canary deployment for a new version.
  16. Enable zero downtime deployment strategy.
  17. Use Feature Flags with LaunchDarkly.
  18. Monitor deployments using Azure Monitor.
  19. Rollback failed deployments.
  20. Use Dapr for sidecar deployment pattern.

๐Ÿงฑ H. Patterns, Governance, and Architecture (20)

  1. Apply API Gateway pattern using YARP or Ocelot.
  2. Implement Backend-for-Frontend (BFF) pattern.
  3. Create Aggregator microservice.
  4. Design microservices around business capabilities.
  5. Apply the Strangler Fig pattern to break a monolith.
  6. Design microservices to support multitenancy.
  7. Use DDD + Event Sourcing + CQRS in a service.
  8. Apply hexagonal architecture in a microservice.
  9. Create a shared library with common models.
  10. Avoid tight coupling using DTOs.
  11. Explain data ownership between services.
  12. Use API contracts with version control.
  13. Implement eventual consistency using events.
  14. Avoid shared databases – demonstrate with example.
  15. Apply service mesh (Istio or Linkerd) to microservices.
  16. Secure public-facing vs internal APIs.
  17. Handle partial failures in distributed transactions.
  18. Apply 12-factor app principles in .NET apps.
  19. Maintain backward compatibility in message schemas.
  20. How do you handle schema evolution in contracts?

๐Ÿ“ฆ I. Database and Data Consistency (20)

  1. Design service with its own database.
  2. Demonstrate DB-per-service in a shopping cart scenario.
  3. Use EF Core in code-first approach.
  4. Use database migrations in .NET apps.
  5. Implement eventual consistency using delayed events.
  6. Implement shared read models.
  7. Use Dapper with repository pattern.
  8. Implement read optimization with Redis.
  9. Apply optimistic concurrency in EF Core.
  10. Handle distributed transactions using Saga pattern.
  11. Create snapshot store for event sourcing.
  12. Write audit logs to a separate database.
  13. Perform schema validation on startup.
  14. Use Cosmos DB with microservices.
  15. Secure data access using stored procedures.
  16. Implement sharding across services.
  17. Use PostgreSQL for identity service.
  18. Enforce foreign key constraints via code.
  19. How to perform bulk inserts efficiently in .NET?
  20. Handle failover and recovery in DB connections. 

Comments

Popular posts from this blog

⚡ Part 1: Introduction to Generics in C#

๐ŸŒ Why Do We Need Generics? Imagine you want to create a stack (like a pile of books ๐Ÿ“š): You can push items on top You can pop items off the top If we write a stack for integers : public class IntStack { private int[] items = new int[10]; private int index = 0; public void Push(int item) => items[index++] = item; public int Pop() => items[--index]; } ๐Ÿ‘‰ Problem: This only works for int . What if we want a string stack ? Or a Customer stack ? We’d have to duplicate code for every type. ๐Ÿ˜ข ✅ Solution: Generics Generics let us create type-safe reusable code without duplication. We can say: “I don’t care what type it is yet — I’ll decide later.” 1) Generic Classes Here’s a generic stack : // Generic class "Stack<T>" // The <T> is a placeholder for any type public class Stack<T> { private T[] items = new T[10]; // Array of type T private int index = 0; // Push adds an item of type T public void P...

๐Ÿšช Part 9: API Gateway for .NET 8 Microservices (Ocelot & YARP)

Once you have multiple microservices (Products, Orders, Payments…), exposing each one directly to clients gets messy: Different base URLs Duplicated auth logic No unified rate limiting / caching Hard to evolve routes or aggregate data ๐Ÿ‘‰ Enter the API Gateway — your single front door for all microservices. An API Gateway handles: ✅ Routing & path rewriting ✅ Load balancing, retries, circuit breakers ✅ Authentication & Authorization (JWT, OAuth2) ✅ Rate limiting & caching ✅ Aggregation (compose results from multiple services) In this post we’ll implement two strong options: Ocelot → config-driven, mature, DevOps-friendly YARP (Yet Another Reverse Proxy) → Microsoft’s code-first, extensible gateway ⚖️ Ocelot vs YARP — When to Choose Ocelot → JSON config, minimal C#, built-in QoS (rate limit, circuit breaker). Perfect for teams that like DevOps config-as-code. YARP → full C# control, middleware-friendly, can embed into broader apps (e.g. add dashb...