Untitled Deck Flashcards

(30 cards)

1
Q

What design principle does using a configuration object like LenderApiOptions support?

A

Config-driven design, allowing runtime environment flexibility without code changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why would you define an interface like ILenderApiService in a service-oriented architecture?

A

To enable mocking, testing, and abstraction from the concrete implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the benefit of using a strongly typed return model like MortgageRateResponse?

A

It ensures type safety, self-documenting code, and easier maintenance downstream.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why is using HttpClient via dependency injection preferable over creating new instances manually?

A

It ensures reuse, avoids socket exhaustion, and supports configuration via factory extensions like Polly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What advantage does structured logging with message templates (e.g., {LenderId}) provide?

A

Enables efficient log querying, structured diagnostics, and better observability.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Why should CancellationToken be included in async methods?

A

To allow graceful cancellation of operations, aiding scalability and responsiveness.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does EnsureSuccessStatusCode() help prevent in HTTP responses?

A

It forces a fast fail if the HTTP status code is not successful, preventing invalid deserialization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What benefit does using var response = await … bring in HTTP calls?

A

It ensures the HttpResponseMessage is properly disposed of to avoid memory leaks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Why catch HttpRequestException separately in an API call?

A

To distinguish transient network errors from more critical failures and apply different handling logic.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What’s the purpose of logging both warnings and errors distinctly in service calls?

A

It helps differentiate between recoverable/transient issues and serious system faults.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can Polly enhance HTTP client resilience?

A

By adding retries, circuit breakers, and fallback strategies to handle transient failures.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What’s a clean way to add authentication headers to outgoing HTTP requests?

A

Use a DelegatingHandler or configure it via HttpClientFactory for automatic token injection.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Why integrate OpenTelemetry spans around external service calls?

A

To trace requests end-to-end across distributed systems for better observability and debugging.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What risks arise from instantiating HttpClient manually instead of using DI?

A

Manual instantiation can lead to socket exhaustion due to unclosed connections and missing lifecycle control.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What’s the benefit of separating configuration into an Options class bound via IOptions<T>?</T>

A

It promotes separation of concerns, centralizes configuration, and simplifies testing.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why should services avoid directly reading configuration values (e.g., Configuration[“…”]) inline?

A

It reduces testability and tightens coupling to configuration sources, violating SRP.

17
Q

Why is it important for services to be interface-backed in unit testing?

A

To enable mocking/stubbing dependencies and testing behavior in isolation.

18
Q

What makes a return type like Task<T?> preferable to throwing in some service failures?

A

It allows downstream services to handle missing data gracefully without exceptions, improving robustness.

19
Q

What should be considered when using JsonSerializer.Deserialize<T> in production services?</T>

A

Handle nulls, malformed data, versioning, and potential casing/property name mismatches.

20
Q

What happens if response.Content.ReadAsStringAsync() is called after the HttpResponseMessage is disposed?

A

It throws an ObjectDisposedException, since the response stream is no longer accessible.

21
Q

What’s a common improvement when deserializing JSON in typed models?

A

Add JsonPropertyName attributes or use a JsonSerializerOptions with naming policies for casing consistency.

22
Q

Why separate transient errors from fatal ones in error handling logic?

A

To allow retries or fallbacks on recoverable issues while alerting on critical faults.

23
Q

How can you prevent a flood of error logs in a failing dependency scenario?

A

Use rate-limited logging, circuit breakers, or aggregate health checks with thresholds.

24
Q

When should retry logic not be used with HTTP requests?

A

When calling non-idempotent endpoints (e.g., POST/PUT that modify state), unless the endpoint is retry-safe.

25
What is a common pattern for tracing and monitoring outgoing HTTP calls?
Wrap them in OpenTelemetry spans or use a middleware/delegating handler to auto-attach trace IDs.
26
How can correlation IDs improve observability across distributed services?
They enable tracking a request across systems, logs, and traces for full end-to-end visibility.
27
What are good ways to expose retry behavior and metrics in production?
Export metrics via Prometheus, include retry counts in structured logs, or expose health endpoints with retry state.
28
Why keep the core service logic free of cross-cutting concerns like auth or retries?
It ensures single responsibility, easier unit testing, and pluggability via handlers or middleware.
29
Why avoid catching general Exception types without rethrowing or logging properly?
It can swallow important diagnostics, make root-cause analysis harder, and obscure true failure modes.
30
What’s a drawback of relying solely on EnsureSuccessStatusCode() without reading the response body on error?
You may miss informative error messages returned in the response content, useful for debugging or UX.