diff --git a/CLAUDE.md b/CLAUDE.md index 79f403cc..a32a96d7 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -163,6 +163,27 @@ Do not use `gh cache delete --all`: it also removes the entries the current poli images `ubi9/dotnet-100:9.8-1791421718` and `ubi9/dotnet-100-aspnet:9.8-1791363520`, held on ubi9 because Red Hat publishes no ubi10 .NET image; every NuGet package pinned exactly); Python (FastAPI, **aiokafka**, **faust-streaming** for stateful processing, grpcio). +- **Idiomatic framework features (S13; do not hand-roll what the framework provides):** + - Schema: `db/init` owns every schema. Hibernate runs `validate`; EF Core has no migrations and no + `EnsureCreated`. HTTP responses are DTOs, never serialized entities. + - Quarkus: Hibernate ORM with Panache (JSONB via `@JdbcTypeCode(SqlTypes.JSON)` plus + `quarkus.hibernate-orm.mapping.format.global=ignore`); SmallRye Health on `/healthz` and `/readyz`; + `quarkus.shutdown.delay` for draining; REST Client, never `java.net.http`; `@RestPath`/`@RestQuery`/`@RestHeader` + with `true` in the compiler plugin (a REST client is not registered without it); + `@ServerExceptionMapper`. + - Spring Boot: Spring Data JPA (`open-in-view=false`); Actuator health groups on `/healthz` and `/readyz`; + `server.shutdown=graceful` plus a `SmartLifecycle` drain bean; `ProblemDetail`; Spring Kafka JSON serdes; + `RestClient`; Spring Cache for read-through only. + - .NET: EF Core `DbContext`; `AddHealthChecks` + `MapHealthChecks`; `IHostedLifecycleService` for draining; + `BackgroundService` for consumers and workers; IConfiguration/Options; typed `AddHttpClient`; + `AddProblemDetails`; `ILogger`; HybridCache for read-through only. + - Python: uv with `pyproject.toml` and a committed `uv.lock`; pydantic-settings for configuration. + - Caching (25): the framework cache serves read-through only; the other strategies keep explicit Redis + clients so they can report `"source"` and survive a Redis outage. + - Go: `any`, not `interface{}` (generated `*.pb.go` files excepted). C++ logging: Drogon services use + Drogon's `LOG_*`; services without Drogon use spdlog. `std::cout`/`std::cerr` only for CLI and test output. + Adding a Conan dependency to an existing lock uses `conan lock create --lockfile=conan.lock + --lockfile-partial`, so the other pins stay. ## House test tools (prefer these; don't introduce alternatives) diff --git a/_docs/02-communications.md b/_docs/02-communications.md index c55e62ae..be9a7270 100644 --- a/_docs/02-communications.md +++ b/_docs/02-communications.md @@ -413,5 +413,5 @@ The code is in [`examples/02-communications/`](https://github.com/patterncatalys it; its `README.md` covers what it does and how to drive it. --- -*Verification status: verified — [`examples/02-communications/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/02-communications/) passes 10/10 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/02-communications/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/02-communications/) passes 10/10 checks in each of the six languages on Docker Engine (2026-10-12) (REST create and validation (201, 422), cursor pagination, order confirmation and rejection driven by the gRPC stock reservation, a GraphQL orders query, and the order.placed Kafka topic).* diff --git a/_docs/03-composition.md b/_docs/03-composition.md index c31af32c..e8ef7a5d 100644 --- a/_docs/03-composition.md +++ b/_docs/03-composition.md @@ -273,5 +273,5 @@ The code is in [`examples/03-composition/`](https://github.com/patterncatalyst/c its `README.md` covers what it does and how to drive it. --- -*Verification status: verified — [`examples/03-composition/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/03-composition/) passes 8/8 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/03-composition/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/03-composition/) passes 8/8 checks in each of the six languages on Docker Engine (2026-10-12) (GraphQL gateway fan-out to the REST order API and the gRPC stock service, selective stock-field resolution, DataLoader batching of stock lookups into one gRPC call, single-order lookup).* diff --git a/_docs/04-data.md b/_docs/04-data.md index 4f07d0bd..4e42e998 100644 --- a/_docs/04-data.md +++ b/_docs/04-data.md @@ -331,5 +331,5 @@ The code is in [`examples/04-data/`](https://github.com/patterncatalyst/cloud-na `README.md` covers what it does and how to drive it. --- -*Verification status: verified — [`examples/04-data/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/04-data/) passes 8/8 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/04-data/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/04-data/) passes 8/8 checks in each of the six languages on Docker Engine (2026-10-12) (transactional write of order and outbox row, Debezium outbox connector running, relay of the outbox event to the order.placed Kafka topic with its payload).* diff --git a/_docs/05-event-driven.md b/_docs/05-event-driven.md index ec79892a..e03082fe 100644 --- a/_docs/05-event-driven.md +++ b/_docs/05-event-driven.md @@ -1295,5 +1295,5 @@ it; its `README.md` covers what it does and how to drive it. The same example, w the Strimzi operator, also runs on a Kubernetes cluster; Appendix R covers that deployment on minikube and Appendix S covers OpenShift Local. --- -*Verification status: verified — [`examples/05-event-driven/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/05-event-driven/) passes 10/10 checks in each of the six languages on Docker Engine (2026-10-10) and on minikube (2026-10-11, Appendix R), and 10/10 in five languages on OpenShift Local 4.22.14 (2026-10-11, Appendix S) +*Verification status: verified — [`examples/05-event-driven/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/05-event-driven/) passes 10/10 checks in each of the six languages on Docker Engine (2026-10-12) and on minikube (2026-10-11, Appendix R), and 10/10 in five languages on OpenShift Local 4.22.14 (2026-10-11, Appendix S) (event publication to order.placed, fan-out to two independent consumer groups (shipping and notification), and idempotent consumers under a redelivered duplicate event).* diff --git a/_docs/06-stream-processing.md b/_docs/06-stream-processing.md index b3bab260..bf7f2807 100644 --- a/_docs/06-stream-processing.md +++ b/_docs/06-stream-processing.md @@ -339,5 +339,5 @@ The code is in [`examples/06-stream-processing/`](https://github.com/patterncata runs it; its `README.md` covers what it does and how to drive it. --- -*Verification status: verified — [`examples/06-stream-processing/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/06-stream-processing/) passes 11/11 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/06-stream-processing/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/06-stream-processing/) passes 11/11 checks in each of the six languages on Docker Engine (2026-10-12) (per-merchant revenue aggregation onto a derived Kafka topic, the stream-processor consumer group, consumer lag that builds while the processor is paused and drains on resume, and the burst appearing in the revenue stream).* diff --git a/_docs/09-api-registry.md b/_docs/09-api-registry.md index 5f5edeaf..efc7336f 100644 --- a/_docs/09-api-registry.md +++ b/_docs/09-api-registry.md @@ -340,5 +340,5 @@ breaking change failing the build and the additive change passing it is the enti point of the registry. --- -*Verification status: verified — [`examples/09-api-registry/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/09-api-registry/) passes 8/8 checks on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/09-api-registry/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/09-api-registry/) passes 8/8 checks on Docker Engine (2026-10-12) (schema registration, BACKWARD compatibility rule, rejection of a breaking change with 400, acceptance of an additive change, versioned retrieval).* diff --git a/_docs/11-observability.md b/_docs/11-observability.md index 9a873ff6..67bbd7e2 100644 --- a/_docs/11-observability.md +++ b/_docs/11-observability.md @@ -442,5 +442,5 @@ the rest. Seeing one request as one waterfall is the moment observability stops being three disconnected tools. --- -*Verification status: verified — [`examples/11-observability/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/11-observability/) passes 10/10 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/11-observability/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/11-observability/) passes 10/10 checks in each of the six languages on Docker Engine (2026-10-12) (trace propagation, metric export, structured log correlation, LGTM stack integration).* diff --git a/_docs/12-security.md b/_docs/12-security.md index 928c297b..77287bda 100644 --- a/_docs/12-security.md +++ b/_docs/12-security.md @@ -726,5 +726,5 @@ step pre-merge. A request without identity being refused, and an unsigned image being blocked twice, is the layered model working. --- -*Verification status: verified — [`examples/12-security/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/12-security/) passes 16/16 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/12-security/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/12-security/) passes 16/16 checks in each of the six languages on Docker Engine (2026-10-12) (sidecar identity trust (403 without X-Forwarded-Client-Cert, health-check bypass), propagation of the JWT subject claim, valet-key mint, verify and tamper rejection, per-tenant bulkhead state, and conftest Rego policy evaluation of a good and a bad manifest. JWT signature validation, RBAC enforcement and rate limiting are not covered).* diff --git a/_docs/16-appendix-c-websockets.md b/_docs/16-appendix-c-websockets.md index 4ca924a0..046dff68 100644 --- a/_docs/16-appendix-c-websockets.md +++ b/_docs/16-appendix-c-websockets.md @@ -555,5 +555,5 @@ Deployment down by one and confirm the dropped clients reconnect with backoff an resume from their last sequence rather than losing the stream. --- -*Verification status: verified — [`examples/16-websockets/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/16-websockets/) passes 6/6 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/16-websockets/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/16-websockets/) passes 6/6 checks in each of the six languages on Docker Engine (2026-10-12) (WebSocket connect, cross-pod delivery and broadcast over the Redis pub/sub backplane, monotonic sequence numbers).* diff --git a/_docs/17-appendix-d-sagas.md b/_docs/17-appendix-d-sagas.md index 602c57a8..72b77823 100644 --- a/_docs/17-appendix-d-sagas.md +++ b/_docs/17-appendix-d-sagas.md @@ -328,5 +328,5 @@ inverses over only the completed steps, plus a clean resume, shows the saga works. --- -*Verification status: verified — [`examples/17-sagas/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/17-sagas/) passes 11/11 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/17-sagas/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/17-sagas/) passes 11/11 checks in each of the six languages on Docker Engine (2026-10-12) (orchestrated saga happy path, compensation in reverse order on failure, skipped compensation for steps that never completed, resume of a RUNNING saga after an orchestrator restart).* diff --git a/_docs/18-appendix-e-errors.md b/_docs/18-appendix-e-errors.md index 3029aa76..268af6b5 100644 --- a/_docs/18-appendix-e-errors.md +++ b/_docs/18-appendix-e-errors.md @@ -853,5 +853,5 @@ load. A flat downstream-call line under rising pressure is the retry budget and doing their job; a climbing one means a control is missing. --- -*Verification status: verified — [`examples/18-errors/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/18-errors/) passes 13/13 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/18-errors/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/18-errors/) passes 13/13 checks in each of the six languages on Docker Engine (2026-10-12) (RFC 9457 problem details over REST for validation (422), stock conflict (409) and upstream unavailable (503), with error codes, traceId, retryable and retryAfter fields).* diff --git a/_docs/19-appendix-f-ddd-hexagonal.md b/_docs/19-appendix-f-ddd-hexagonal.md index feacdf1f..da9bb5e3 100644 --- a/_docs/19-appendix-f-ddd-hexagonal.md +++ b/_docs/19-appendix-f-ddd-hexagonal.md @@ -354,5 +354,5 @@ new adapter file appears. A clean domain import list plus a no-domain-change dif you bolt on a protocol is hexagonal architecture holding. --- -*Verification status: verified — [`examples/19-ddd-hexagonal/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/19-ddd-hexagonal/) passes 17/17 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/19-ddd-hexagonal/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/19-ddd-hexagonal/) passes 17/17 checks in each of the six languages on Docker Engine (2026-10-12) (source scans proving the domain layer imports no framework or persistence types, REST and CLI adapters driving the same use case, input validation, OrderPlaced event emission).* diff --git a/_docs/21-appendix-h-shutdown.md b/_docs/21-appendix-h-shutdown.md index 004605ee..41913a83 100644 --- a/_docs/21-appendix-h-shutdown.md +++ b/_docs/21-appendix-h-shutdown.md @@ -331,5 +331,5 @@ A clean rollout under live load, not a green integration test, is evidence that works. --- -*Verification status: verified — [`examples/21-graceful-shutdown/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/21-graceful-shutdown/) passes 17/17 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/21-graceful-shutdown/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/21-graceful-shutdown/) passes 17/17 checks in each of the six languages on Docker Engine (2026-10-12) (one SIGTERM, readiness flip to 503, the drain log lines, exit code 0 inside the grace period, a `docker stop` timing check, restart recovery, and orders persisting across the restart. In-flight request draining is not checked by the script).* diff --git a/_docs/22-appendix-i-l7-routing.md b/_docs/22-appendix-i-l7-routing.md index 5345c76a..055093dd 100644 --- a/_docs/22-appendix-i-l7-routing.md +++ b/_docs/22-appendix-i-l7-routing.md @@ -681,5 +681,5 @@ track the config and a ruleset that can move routing without a code change are t this appendix working. --- -*Verification status: verified — [`examples/22-l7-routing/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/22-l7-routing/) passes 15/15 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/22-l7-routing/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/22-l7-routing/) passes 15/15 checks in each of the six languages on Docker Engine (2026-10-12) (Envoy weighted traffic split, header-based routing override, in-app rule-driven routing, and changing routing rules without a redeploy. Canary promotion and circuit breaking are not covered).* diff --git a/_docs/24-appendix-k-monolith-to-microservices.md b/_docs/24-appendix-k-monolith-to-microservices.md index 758bf6b2..6140dac3 100644 --- a/_docs/24-appendix-k-monolith-to-microservices.md +++ b/_docs/24-appendix-k-monolith-to-microservices.md @@ -586,5 +586,5 @@ write *and* that an `order.placed` event landed on Kafka. Same client-visible AP underneath, legacy untouched — that is the decorator doing its job. --- -*Verification status: verified — [`examples/24-monolith-to-microservices/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/24-monolith-to-microservices/) passes 19/19 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/24-monolith-to-microservices/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/24-monolith-to-microservices/) passes 19/19 checks in each of the six languages on Docker Engine (2026-10-12) (strangler fig router with per-tenant routing, reversible cutover, a decorating collaborator adding caching and Kafka event emission, and an untouched legacy service).* diff --git a/_docs/25-appendix-l-caching.md b/_docs/25-appendix-l-caching.md index 48ae8645..16142b4d 100644 --- a/_docs/25-appendix-l-caching.md +++ b/_docs/25-appendix-l-caching.md @@ -1225,5 +1225,5 @@ the new value with no DB round trip; for write-around, write then read and confi miss (the DB log shows the `SELECT`) while the second is a hit. --- -*Verification status: verified — [`examples/25-caching/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/25-caching/) passes 29/29 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/25-caching/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/25-caching/) passes 29/29 checks in each of the six languages on Docker Engine (2026-10-12) (cache-aside with invalidation on update, read-through, write-through, write-around, write-back with 202 and a flush retry across a Postgres outage, refresh-ahead, hot-set tracking, and degradation with Redis stopped and restarted).* diff --git a/_docs/26-appendix-m-failure-modes.md b/_docs/26-appendix-m-failure-modes.md index 6554928e..798ac9ee 100644 --- a/_docs/26-appendix-m-failure-modes.md +++ b/_docs/26-appendix-m-failure-modes.md @@ -750,5 +750,5 @@ This appendix touches difficult operational territory; if you are diagnosing a l Google SRE cascading-failures chapter is the fastest way to a shared vocabulary with your team. --- -*Verification status: verified — [`examples/26-failure-modes/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/26-failure-modes/) passes 20/20 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/26-failure-modes/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/26-failure-modes/) passes 20/20 checks in each of the six languages on Docker Engine (2026-10-12) (timeout, retry exhaustion, circuit breaker closed, open and recovered with fallback, deadline-budget propagation, bulkhead limit).* diff --git a/_docs/27-appendix-n-feature-flags.md b/_docs/27-appendix-n-feature-flags.md index d66bf7dc..7c2af5f4 100644 --- a/_docs/27-appendix-n-feature-flags.md +++ b/_docs/27-appendix-n-feature-flags.md @@ -417,5 +417,5 @@ lookup is on a critical path without a default, which is the one feature-flag mi ship. --- -*Verification status: verified — [`examples/27-feature-flags/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/27-feature-flags/) passes 14/14 checks in each of the six languages on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/27-feature-flags/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/27-feature-flags/) passes 14/14 checks in each of the six languages on Docker Engine (2026-10-12) (plan-based targeting rules, sticky assignment and percentage rollout, kill switch, simple boolean flag, flag listing, and safe defaults while flagd is down).* diff --git a/_docs/28-appendix-o-newman.md b/_docs/28-appendix-o-newman.md index a15918e6..dadc8511 100644 --- a/_docs/28-appendix-o-newman.md +++ b/_docs/28-appendix-o-newman.md @@ -276,5 +276,5 @@ service and fails against one that wrongly accepts it. A suite that goes red on break, and only then, is the whole value of this appendix. --- -*Verification status: verified — [`examples/28-newman/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/28-newman/) passes 11/11 checks on Docker Engine (2026-10-10) +*Verification status: verified — [`examples/28-newman/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/28-newman/) passes 11/11 checks on Docker Engine (2026-10-12) (a Newman collection run with status-code and state assertions (201, 422, 404, 204, cancel) and JUnit XML export).* diff --git a/_docs/30-appendix-q-blazor-signalr.md b/_docs/30-appendix-q-blazor-signalr.md index 08c13408..90f40de4 100644 --- a/_docs/30-appendix-q-blazor-signalr.md +++ b/_docs/30-appendix-q-blazor-signalr.md @@ -179,4 +179,4 @@ The code is in [`examples/30-blazor-signalr/`](https://github.com/patterncatalys runs it; its `README.md` covers what it does and how to drive it. --- -*Verification status: verified — [`examples/30-blazor-signalr/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/30-blazor-signalr/) passes 10/10 checks on Docker Engine (2026-10-10): health, order placement and listing, the dashboard page, the SignalR negotiate endpoint, a second dashboard instance, Redis backplane delivery in both directions between the two instances (a SignalR client on one receives an order posted to the other), orders listed across instances, and backplane delivery to a restarted instance (the script asserts the container's start time changed and it returned healthy). Blazor circuit reconnection is the framework default and is not covered by the script.* +*Verification status: verified — [`examples/30-blazor-signalr/`](https://github.com/patterncatalyst/cloud-native-design-patterns/tree/main/examples/30-blazor-signalr/) passes 10/10 checks on Docker Engine (2026-10-12): health, order placement and listing, the dashboard page, the SignalR negotiate endpoint, a second dashboard instance, Redis backplane delivery in both directions between the two instances (a SignalR client on one receives an order posted to the other), orders listed across instances, and backplane delivery to a restarted instance (the script asserts the container's start time changed and it returned healthy). Blazor circuit reconnection is the framework default and is not covered by the script.* diff --git a/_plans/modernization-plan.md b/_plans/modernization-plan.md index 9156afdf..bfcd7a48 100644 --- a/_plans/modernization-plan.md +++ b/_plans/modernization-plan.md @@ -35,7 +35,7 @@ Each step gets its own branch, a PR, green CI and a squash-merge before the next | S10 | feature/openshift-local-appendix | 8 | done (PR #68, 48e7736) | | S11 | docs/professional-voice | 9 | done (PR #69, 2d8c2a8) | | S12 | docs/deck-refresh | 10 (expanded 2026-10-11) | done (plan: _plans/s12-deck-refresh-plan.md; examples 01, 21, 25 fixed and verified 6/6) | -| S13 | refactor/idiomatic-examples (5 PRs) | 11 (added 2026-10-12) | in progress (plan: _plans/s13-idiomatic-plan.md) | +| S13 | refactor/idiomatic-examples (5 PRs) | 11 (added 2026-10-12) | done (PRs #73-#77; 111/111 PASS 2026-10-12; plan: _plans/s13-idiomatic-plan.md) | | S14 | refactor/resilience-libraries | 12 (added 2026-10-12) | next: circuit breaker, bulkhead, Spring gRPC via libraries | diff --git a/_plans/s13-idiomatic-plan.md b/_plans/s13-idiomatic-plan.md index 730c9233..c5c15ced 100644 --- a/_plans/s13-idiomatic-plan.md +++ b/_plans/s13-idiomatic-plan.md @@ -97,10 +97,10 @@ compatibility). Python: uv 0.13.0, `astral-sh/setup-uv` v10.3.0; package version | 3 | Quarkus batch (about 26 projects) + site tabs + `Quarkus.fix5.json` | 2 | done; matrix 2026-10-12: 23/23 PASS (Quarkus plus 24 in all languages) after three fixes (JSONB format mapper, 19 422 status, `-parameters`) | | 4 | Spring batch (about 26) + site tabs + `Spring.fix6.json` | 3 | done; matrix 2026-10-12: 18/18 Spring Boot PASS | | 5 | .NET batch (about 28) + site tabs + `DotNet.fix6.json` | 4 | done; matrix 2026-10-12: 19/19 .NET PASS | -| 6 | Go (`any`) and C++ (spdlog) + any deck/site follow-ups | 5 | pending | -| 7 | Final full matrix (111 targets, one at a time), footers with verified counts | 5 | pending | -| 8 | CLAUDE.md locked stacks (ORMs, health, shutdown, uv, schema ownership), modernization plan | 5 | pending | -| 9 | Opus validation per PR (re-scan, checklist sample, `db/init` unchanged, three CI checks green) | each | pending | +| 6 | Go (`any`) and C++ (spdlog) + any deck/site follow-ups | 5 | done: Go `any` in 27; C++ Drogon services on `LOG_*` with stdout line-buffered, gRPC inventories and consumers on spdlog 1.17.0 (locks extended with `--lockfile-partial`); `DotNet.fix7.json` (HybridCache, not FusionCache, as the read-through default) | +| 7 | Final full matrix (111 targets, one at a time), footers with verified counts | 5 | done: 111/111 PASS 2026-10-12; 20 footers re-dated, counts unchanged | +| 8 | CLAUDE.md locked stacks (ORMs, health, shutdown, uv, schema ownership), modernization plan | 5 | done | +| 9 | Opus validation per PR (re-scan, checklist sample, `db/init` unchanged, three CI checks green) | each | done: criteria 2-5 by grep, `db/init` unchanged since the plan commit, three checks green on PRs 73-76 | Order inside a batch: 01, 21, 04, 05, 17, 19, 25, then the health-only examples. Run `scripts/verify-matrix.sh NN-x/` after each example (Docker runs strictly one at a time). Decks follow the S12 method (edit files applied once, @@ -136,3 +136,9 @@ asserts; Spring lifecycle phase versus `WebServerGracefulShutdownLifecycle`; Hib and Kafka payload drift (DTOs only, compare with kcat); idempotent consumers under JPA/EF rollback; Hibernate/EF memory and start time against compose `--wait` and the 05 k8s limits; deck `expect` counts (measure on committed decks); Python lock drift (diff `uv export` against the old pins); long matrix runs. + +## Not re-run + +Example 05 on minikube (Appendix R) and OpenShift Local (Appendix S) was not repeated after S13 (D7). Its +Quarkus, Spring Boot and .NET services changed (ORMs, health endpoints), so those two footers describe the +pre-S13 code; the deploy scripts accept the new `"UP"` health bodies. diff --git a/examples/02-communications/cpp/inventory-service/CMakeLists.txt b/examples/02-communications/cpp/inventory-service/CMakeLists.txt index 591e0396..26703100 100644 --- a/examples/02-communications/cpp/inventory-service/CMakeLists.txt +++ b/examples/02-communications/cpp/inventory-service/CMakeLists.txt @@ -15,6 +15,7 @@ set(CMAKE_CXX_LINK_EXECUTABLE find_package(gRPC CONFIG REQUIRED) find_package(protobuf CONFIG REQUIRED) +find_package(spdlog CONFIG REQUIRED) find_package(Threads REQUIRED) set(PROTO_SRC "${CMAKE_SOURCE_DIR}/../proto/inventory.proto") @@ -42,4 +43,5 @@ target_include_directories(inventory-service PRIVATE ${PROTO_OUT}) target_link_libraries(inventory-service PRIVATE gRPC::grpc++ protobuf::protobuf + spdlog::spdlog Threads::Threads) diff --git a/examples/02-communications/cpp/inventory-service/conan.lock b/examples/02-communications/cpp/inventory-service/conan.lock index 601bfcf7..d4c4377f 100644 --- a/examples/02-communications/cpp/inventory-service/conan.lock +++ b/examples/02-communications/cpp/inventory-service/conan.lock @@ -2,10 +2,12 @@ "version": "0.5", "requires": [ "zlib/1.3.2#1cb806da49011867778ffb6ac7190fcb%1777558780.503", + "spdlog/1.17.0#bcbaaf7147bda6ad24ffbd1ac3d7142c%1767636069.964", "re2/20251105#8579cfd0bda4daf0683f9e3898f964b4%1772560729.95", "protobuf/6.33.5#ca5ff466767b31a1b496ec60247e105c%1785159690.783", "openssl/3.6.5#3c1311f37543e7140f33fe5989f315c2%1790692982.113", "grpc/1.84.0#c7c2ff9ed88b66eac8b8399c96d8df2c%1789729270.871", + "fmt/12.2.0#b445244e6d0151a425e229248cd2bed8%1785754552.386", "c-ares/1.34.8#074b97a9e38159813ed5e2dcfeb290ca%1784539118.141", "abseil/20260107.1#883e95a7be2b767999f64669ac642e5d%1773137897.755" ], @@ -16,5 +18,10 @@ "abseil/20260107.1#883e95a7be2b767999f64669ac642e5d%1773137897.755" ], "python_requires": [], + "overrides": { + "fmt/12.1.0": [ + "fmt/12.2.0" + ] + }, "config_requires": [] } diff --git a/examples/02-communications/cpp/inventory-service/conanfile.py b/examples/02-communications/cpp/inventory-service/conanfile.py index 0f834de3..c4dc8081 100644 --- a/examples/02-communications/cpp/inventory-service/conanfile.py +++ b/examples/02-communications/cpp/inventory-service/conanfile.py @@ -17,3 +17,5 @@ class Cndp02CommunicationsCppInventoryServiceConan(ConanFile): def requirements(self): self.requires("grpc/1.84.0") self.requires("protobuf/6.33.5") + self.requires("spdlog/1.17.0") + self.requires("fmt/12.2.0", override=True) # spdlog pins fmt 12.1.0 diff --git a/examples/02-communications/cpp/inventory-service/src/main.cpp b/examples/02-communications/cpp/inventory-service/src/main.cpp index 79b56e76..6dd5028e 100644 --- a/examples/02-communications/cpp/inventory-service/src/main.cpp +++ b/examples/02-communications/cpp/inventory-service/src/main.cpp @@ -1,8 +1,8 @@ #include +#include #include "inventory.grpc.pb.h" #include #include -#include static std::mutex g_mu; static std::unordered_map g_stock; @@ -21,15 +21,12 @@ class InventoryServiceImpl final : public inventory::Inventory::Service { stock = remaining; reply->set_reserved(true); reply->set_remaining(remaining); - std::cerr << "reserved sku=" << req->sku() - << " qty=" << req->quantity() - << " remaining=" << remaining << std::endl; + spdlog::info("reserved sku={} qty={} remaining={}", req->sku(), req->quantity(), remaining); } else { reply->set_reserved(false); reply->set_remaining(stock); - std::cerr << "insufficient stock sku=" << req->sku() - << " requested=" << req->quantity() - << " available=" << stock << std::endl; + spdlog::info("insufficient stock sku={} requested={} available={}", + req->sku(), req->quantity(), stock); } return grpc::Status::OK; } @@ -45,7 +42,7 @@ int main() { builder.AddListeningPort(addr, grpc::InsecureServerCredentials()); builder.RegisterService(&service); auto server = builder.BuildAndStart(); - std::cerr << "inventory gRPC server listening on " << addr << std::endl; + spdlog::info("inventory gRPC server listening on {}", addr); server->Wait(); return 0; } diff --git a/examples/02-communications/cpp/order-service/src/kafka_publisher.hpp b/examples/02-communications/cpp/order-service/src/kafka_publisher.hpp index 33979442..37bba9fc 100644 --- a/examples/02-communications/cpp/order-service/src/kafka_publisher.hpp +++ b/examples/02-communications/cpp/order-service/src/kafka_publisher.hpp @@ -7,13 +7,13 @@ #pragma once #include -#include #include #include #include #include #include +#include namespace cndp { @@ -51,7 +51,7 @@ class OrderPublisher { topic_, RdKafka::Topic::PARTITION_UA, RdKafka::Producer::RK_MSG_COPY, const_cast(payload.data()), payload.size(), nullptr, 0, 0, nullptr); if (rc != RdKafka::ERR_NO_ERROR) { - std::cerr << "kafka produce failed: " << RdKafka::err2str(rc) << std::endl; + LOG_ERROR << "kafka produce failed: " << RdKafka::err2str(rc); return false; } return true; @@ -62,7 +62,7 @@ class OrderPublisher { public: void dr_cb(RdKafka::Message& m) override { if (m.err() != RdKafka::ERR_NO_ERROR) { - std::cerr << "kafka delivery failed topic=" << m.topic_name() << ": " << m.errstr() << std::endl; + LOG_ERROR << "kafka delivery failed topic=" << m.topic_name() << ": " << m.errstr(); } } }; diff --git a/examples/02-communications/cpp/order-service/src/main.cpp b/examples/02-communications/cpp/order-service/src/main.cpp index 7d5b301e..c28be2c0 100644 --- a/examples/02-communications/cpp/order-service/src/main.cpp +++ b/examples/02-communications/cpp/order-service/src/main.cpp @@ -7,8 +7,8 @@ // cppgraphqlgen GraphQL schema, generated resolvers (src/graphql/) // rdkafka++ order.placed producer with delivery reports +#include #include -#include #include #include #include @@ -59,12 +59,14 @@ const char* env_or(const char* name, const char* fallback) { } // namespace int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); std::shared_ptr repo; try { repo = std::make_shared( env_or("PG_CONNINFO", "host=postgres port=5432 dbname=appdb user=appuser password=apppass")); } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + LOG_ERROR << e.what(); return 1; } @@ -77,7 +79,7 @@ int main() { publisher = std::make_unique(env_or("KAFKA_BOOTSTRAP", "kafka:9094"), "order.placed"); } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + LOG_ERROR << e.what(); return 1; } @@ -130,7 +132,7 @@ int main() { try { repo->insert(order); } catch (const std::exception& e) { - std::cerr << "order insert failed: " << e.what() << std::endl; + LOG_ERROR << "order insert failed: " << e.what(); cb(status_only(k500InternalServerError)); return; } @@ -139,7 +141,7 @@ int main() { wb["indentation"] = ""; publisher->publish(Json::writeString(wb, to_json(order))); - std::cerr << "order created id=" << order.id << " status=" << order.status << std::endl; + LOG_INFO << "order created id=" << order.id << " status=" << order.status; auto resp = HttpResponse::newHttpJsonResponse(to_json(order)); resp->setStatusCode(k201Created); cb(resp); @@ -160,7 +162,7 @@ int main() { try { orders = repo->list(limit, req->getParameter("after")); } catch (const std::exception& e) { - std::cerr << "order query failed: " << e.what() << std::endl; + LOG_ERROR << "order query failed: " << e.what(); cb(status_only(k500InternalServerError)); return; } diff --git a/examples/03-composition/cpp/gateway/src/main.cpp b/examples/03-composition/cpp/gateway/src/main.cpp index 0df01b92..180521e8 100644 --- a/examples/03-composition/cpp/gateway/src/main.cpp +++ b/examples/03-composition/cpp/gateway/src/main.cpp @@ -8,11 +8,11 @@ // worker thread instead of on a Drogon event-loop thread. #include +#include #include #include #include #include -#include #include #include #include @@ -131,6 +131,8 @@ class WorkerPool { } // namespace int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); auto channel = grpc::CreateChannel(env_or("INVENTORY_ADDR", "inventory:50051"), grpc::InsecureChannelCredentials()); std::shared_ptr inventory_stub = inventory::Inventory::NewStub(channel); @@ -144,12 +146,12 @@ int main() { grpc::ClientContext ctx; auto status = inventory_stub->GetStockBatch(&ctx, req, &reply); if (!status.ok()) { - std::cerr << "inventory GetStockBatch failed: " << status.error_message() << std::endl; + LOG_ERROR << "inventory GetStockBatch failed: " << status.error_message(); return std::nullopt; } std::unordered_map result; for (const auto& item : reply.items()) result[item.sku()] = item.available(); - std::cerr << "DataLoader batched " << skus.size() << " skus in one gRPC call" << std::endl; + LOG_INFO << "DataLoader batched " << skus.size() << " skus in one gRPC call"; return result; }; @@ -159,7 +161,7 @@ int main() { const auto workers = static_cast(std::atoi(env_or("GATEWAY_WORKERS", "16"))); auto pool = std::make_shared(workers > 0 ? workers : 16, 256); - std::cerr << "gateway started" << std::endl; + LOG_INFO << "gateway started"; app().setLogLevel(trantor::Logger::kInfo); app().addListener("0.0.0.0", 8080); diff --git a/examples/03-composition/cpp/inventory-service/CMakeLists.txt b/examples/03-composition/cpp/inventory-service/CMakeLists.txt index 591e0396..26703100 100644 --- a/examples/03-composition/cpp/inventory-service/CMakeLists.txt +++ b/examples/03-composition/cpp/inventory-service/CMakeLists.txt @@ -15,6 +15,7 @@ set(CMAKE_CXX_LINK_EXECUTABLE find_package(gRPC CONFIG REQUIRED) find_package(protobuf CONFIG REQUIRED) +find_package(spdlog CONFIG REQUIRED) find_package(Threads REQUIRED) set(PROTO_SRC "${CMAKE_SOURCE_DIR}/../proto/inventory.proto") @@ -42,4 +43,5 @@ target_include_directories(inventory-service PRIVATE ${PROTO_OUT}) target_link_libraries(inventory-service PRIVATE gRPC::grpc++ protobuf::protobuf + spdlog::spdlog Threads::Threads) diff --git a/examples/03-composition/cpp/inventory-service/conan.lock b/examples/03-composition/cpp/inventory-service/conan.lock index 601bfcf7..d4c4377f 100644 --- a/examples/03-composition/cpp/inventory-service/conan.lock +++ b/examples/03-composition/cpp/inventory-service/conan.lock @@ -2,10 +2,12 @@ "version": "0.5", "requires": [ "zlib/1.3.2#1cb806da49011867778ffb6ac7190fcb%1777558780.503", + "spdlog/1.17.0#bcbaaf7147bda6ad24ffbd1ac3d7142c%1767636069.964", "re2/20251105#8579cfd0bda4daf0683f9e3898f964b4%1772560729.95", "protobuf/6.33.5#ca5ff466767b31a1b496ec60247e105c%1785159690.783", "openssl/3.6.5#3c1311f37543e7140f33fe5989f315c2%1790692982.113", "grpc/1.84.0#c7c2ff9ed88b66eac8b8399c96d8df2c%1789729270.871", + "fmt/12.2.0#b445244e6d0151a425e229248cd2bed8%1785754552.386", "c-ares/1.34.8#074b97a9e38159813ed5e2dcfeb290ca%1784539118.141", "abseil/20260107.1#883e95a7be2b767999f64669ac642e5d%1773137897.755" ], @@ -16,5 +18,10 @@ "abseil/20260107.1#883e95a7be2b767999f64669ac642e5d%1773137897.755" ], "python_requires": [], + "overrides": { + "fmt/12.1.0": [ + "fmt/12.2.0" + ] + }, "config_requires": [] } diff --git a/examples/03-composition/cpp/inventory-service/conanfile.py b/examples/03-composition/cpp/inventory-service/conanfile.py index f9efcb1e..2720365a 100644 --- a/examples/03-composition/cpp/inventory-service/conanfile.py +++ b/examples/03-composition/cpp/inventory-service/conanfile.py @@ -17,3 +17,5 @@ class Cndp03CompositionCppInventoryServiceConan(ConanFile): def requirements(self): self.requires("grpc/1.84.0") self.requires("protobuf/6.33.5") + self.requires("spdlog/1.17.0") + self.requires("fmt/12.2.0", override=True) # spdlog pins fmt 12.1.0 diff --git a/examples/03-composition/cpp/inventory-service/src/main.cpp b/examples/03-composition/cpp/inventory-service/src/main.cpp index 8b4ae936..5e0ed180 100644 --- a/examples/03-composition/cpp/inventory-service/src/main.cpp +++ b/examples/03-composition/cpp/inventory-service/src/main.cpp @@ -1,7 +1,8 @@ +#include #include +#include #include "inventory.grpc.pb.h" #include -#include #include static std::unordered_map g_stock = { @@ -21,9 +22,7 @@ class InventoryServiceImpl final : public inventory::Inventory::Service { int available = (it != g_stock.end()) ? it->second : 0; reply->set_sku(req->sku()); reply->set_available(available); - std::cerr << "GetStock sku=" << req->sku() - << " available=" << available - << " (call #" << count << ")" << std::endl; + spdlog::info("GetStock sku={} available={} (call #{})", req->sku(), available, count); return grpc::Status::OK; } @@ -37,12 +36,7 @@ class InventoryServiceImpl final : public inventory::Inventory::Service { auto it = g_stock.find(sku); item->set_available((it != g_stock.end()) ? it->second : 0); } - std::cerr << "GetStockBatch skus=["; - for (int i = 0; i < req->skus_size(); i++) { - if (i > 0) std::cerr << ", "; - std::cerr << req->skus(i); - } - std::cerr << "] (call #" << count << ")" << std::endl; + spdlog::info("GetStockBatch skus=[{}] (call #{})", fmt::join(req->skus(), ", "), count); return grpc::Status::OK; } }; @@ -54,7 +48,7 @@ int main() { builder.AddListeningPort(addr, grpc::InsecureServerCredentials()); builder.RegisterService(&service); auto server = builder.BuildAndStart(); - std::cerr << "inventory gRPC server listening on " << addr << std::endl; + spdlog::info("inventory gRPC server listening on {}", addr); server->Wait(); return 0; } diff --git a/examples/03-composition/cpp/order-api/src/main.cpp b/examples/03-composition/cpp/order-api/src/main.cpp index 900e4217..d8c9131f 100644 --- a/examples/03-composition/cpp/order-api/src/main.cpp +++ b/examples/03-composition/cpp/order-api/src/main.cpp @@ -1,7 +1,7 @@ #include #include +#include #include -#include using namespace drogon; @@ -9,14 +9,16 @@ static PGconn* g_pg = nullptr; static std::mutex g_pg_mu; int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); auto env_pg = std::getenv("PG_CONNINFO"); std::string conninfo = env_pg ? env_pg : "host=postgres port=5432 dbname=appdb user=appuser password=apppass"; g_pg = PQconnectdb(conninfo.c_str()); if (PQstatus(g_pg) != CONNECTION_OK) { - std::cerr << "pg connect failed: " << PQerrorMessage(g_pg) << std::endl; + LOG_ERROR << "pg connect failed: " << PQerrorMessage(g_pg); return 1; } - std::cerr << "order-api started" << std::endl; + LOG_INFO << "order-api started"; app().setLogLevel(trantor::Logger::kInfo); app().addListener("0.0.0.0", 8081); diff --git a/examples/04-data/cpp/order-service/src/main.cpp b/examples/04-data/cpp/order-service/src/main.cpp index 2346da1d..71363cdb 100644 --- a/examples/04-data/cpp/order-service/src/main.cpp +++ b/examples/04-data/cpp/order-service/src/main.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -278,6 +279,8 @@ void signal_handler(int sig) { } int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); // Set up custom signal handler app().registerBeginningAdvice([]() { std::signal(SIGTERM, signal_handler); diff --git a/examples/05-event-driven/cpp/notification-consumer/CMakeLists.txt b/examples/05-event-driven/cpp/notification-consumer/CMakeLists.txt index 2e40b9e6..5d6f1f18 100644 --- a/examples/05-event-driven/cpp/notification-consumer/CMakeLists.txt +++ b/examples/05-event-driven/cpp/notification-consumer/CMakeLists.txt @@ -18,8 +18,9 @@ find_package(RdKafka CONFIG REQUIRED) # librdkafka C++ API (rdkafka++) from Con find_package(jsoncpp CONFIG REQUIRED) find_package(PostgreSQL REQUIRED) # libpq from Conan (direct C client) find_package(opentelemetry-cpp CONFIG REQUIRED) +find_package(spdlog CONFIG REQUIRED) find_package(Threads REQUIRED) add_executable(notification-consumer src/main.cpp) target_include_directories(notification-consumer PRIVATE src) -target_link_libraries(notification-consumer PRIVATE RdKafka::rdkafka++ JsonCpp::JsonCpp PostgreSQL::PostgreSQL opentelemetry-cpp::opentelemetry-cpp Threads::Threads) +target_link_libraries(notification-consumer PRIVATE RdKafka::rdkafka++ JsonCpp::JsonCpp PostgreSQL::PostgreSQL opentelemetry-cpp::opentelemetry-cpp spdlog::spdlog Threads::Threads) diff --git a/examples/05-event-driven/cpp/notification-consumer/conan.lock b/examples/05-event-driven/cpp/notification-consumer/conan.lock index cca59aef..05d4815f 100644 --- a/examples/05-event-driven/cpp/notification-consumer/conan.lock +++ b/examples/05-event-driven/cpp/notification-consumer/conan.lock @@ -2,6 +2,7 @@ "version": "0.5", "requires": [ "zlib/1.3.2#1cb806da49011867778ffb6ac7190fcb%1777558780.503", + "spdlog/1.17.0#bcbaaf7147bda6ad24ffbd1ac3d7142c%1767636069.964", "protobuf/6.33.5#ca5ff466767b31a1b496ec60247e105c%1785159690.783", "opentelemetry-cpp/1.26.0#000b96632e39f3672f8576bf4febb213%1789030194.301", "openssl/3.6.5#3c1311f37543e7140f33fe5989f315c2%1790692982.113", @@ -11,6 +12,7 @@ "libpq/17.11#6161d3be84f5d2bd657dd778eed017c2%1788252336.346", "libcurl/8.22.0#3599f8564660d38f96af52da40795734%1789660092.861", "jsoncpp/1.9.8#5be5e85394fc94f13f6451e5822ea759%1787912339.522", + "fmt/12.2.0#b445244e6d0151a425e229248cd2bed8%1785754552.386", "abseil/20260107.1#883e95a7be2b767999f64669ac642e5d%1773137897.755" ], "build_requires": [ @@ -37,6 +39,9 @@ ], "nlohmann_json/3.11.3": [ "nlohmann_json/3.12.0" + ], + "fmt/12.1.0": [ + "fmt/12.2.0" ] }, "config_requires": [] diff --git a/examples/05-event-driven/cpp/notification-consumer/conanfile.py b/examples/05-event-driven/cpp/notification-consumer/conanfile.py index 82483aec..6e4733c6 100644 --- a/examples/05-event-driven/cpp/notification-consumer/conanfile.py +++ b/examples/05-event-driven/cpp/notification-consumer/conanfile.py @@ -19,6 +19,8 @@ def requirements(self): self.requires("librdkafka/2.14.2") self.requires("jsoncpp/1.9.8") self.requires("opentelemetry-cpp/1.26.0") + self.requires("spdlog/1.17.0") # opentelemetry-cpp pins nlohmann_json 3.11.3; take the newest release. self.requires("nlohmann_json/3.12.0", override=True) self.requires("lz4/1.10.0", override=True) # librdkafka and libpq pin lz4 1.9.4 + self.requires("fmt/12.2.0", override=True) # spdlog pins fmt 12.1.0 diff --git a/examples/05-event-driven/cpp/notification-consumer/src/main.cpp b/examples/05-event-driven/cpp/notification-consumer/src/main.cpp index fdc4078b..9bfd8d1c 100644 --- a/examples/05-event-driven/cpp/notification-consumer/src/main.cpp +++ b/examples/05-event-driven/cpp/notification-consumer/src/main.cpp @@ -5,12 +5,12 @@ #include #include +#include #include #include #include #include -#include #include #include #include @@ -32,12 +32,12 @@ void init_pg() { g_pg_conn = PQconnectdb(conninfo); if (PQstatus(g_pg_conn) != CONNECTION_OK) { - std::cerr << "Postgres connection failed: " << PQerrorMessage(g_pg_conn) << "\n"; + spdlog::error("Postgres connection failed: {}", PQerrorMessage(g_pg_conn)); PQfinish(g_pg_conn); g_pg_conn = nullptr; throw std::runtime_error("Postgres connection failed"); } - std::cout << "Connected to Postgres\n"; + spdlog::info("Connected to Postgres"); } enum class Outcome { Done, Skip, Retry }; @@ -51,16 +51,16 @@ Outcome process_event(const std::string& event_json) { std::istringstream stream(event_json); if (!Json::parseFromStream(builder, stream, &root, &errs)) { - std::cerr << "JSON parse error: " << errs << "\n"; + spdlog::warn("JSON parse error: {}", errs); return Outcome::Skip; } if (!root.isObject() || !root.isMember("id")) { - std::cerr << "Missing 'id' field in event\n"; + spdlog::warn("Missing 'id' field in event"); return Outcome::Skip; } std::string order_id = root["id"].asString(); - std::cout << "Processing order: " << order_id << "\n"; + spdlog::info("Processing order: {}", order_id); if (PQstatus(g_pg_conn) != CONNECTION_OK) PQreset(g_pg_conn); @@ -72,9 +72,9 @@ Outcome process_event(const std::string& event_json) { bool ok = PQresultStatus(res) == PGRES_COMMAND_OK; if (!ok) { - std::cerr << "Insert failed: " << PQerrorMessage(g_pg_conn) << "\n"; + spdlog::error("Insert failed: {}", PQerrorMessage(g_pg_conn)); } else { - std::cout << "Notification created/skipped for order: " << order_id << "\n"; + spdlog::info("Notification created/skipped for order: {}", order_id); } PQclear(res); return ok ? Outcome::Done : Outcome::Retry; @@ -89,7 +89,7 @@ int main() { try { init_pg(); } catch (const std::exception& e) { - std::cerr << "Initialization failed: " << e.what() << "\n"; + spdlog::error("Initialization failed: {}", e.what()); return 1; } @@ -106,32 +106,32 @@ int main() { {"auto.offset.reset", "earliest"}, {"enable.auto.commit", "false"}}) { if (conf->set(key, value, errstr) != RdKafka::Conf::CONF_OK) { - std::cerr << "Kafka config " << key << ": " << errstr << "\n"; + spdlog::error("Kafka config {}: {}", key, errstr); return 1; } } std::unique_ptr consumer(RdKafka::KafkaConsumer::create(conf.get(), errstr)); if (!consumer) { - std::cerr << "Failed to create consumer: " << errstr << "\n"; + spdlog::error("Failed to create consumer: {}", errstr); return 1; } // subscribe() does not fail when the topic is missing: the consumer keeps polling and // picks the partitions up once the producer has created order.placed. if (RdKafka::ErrorCode err = consumer->subscribe({"order.placed"}); err != RdKafka::ERR_NO_ERROR) { - std::cerr << "Subscribe failed: " << RdKafka::err2str(err) << "\n"; + spdlog::error("Subscribe failed: {}", RdKafka::err2str(err)); return 1; } - std::cout << "Successfully subscribed to order.placed topic\n"; - std::cout << "Notification consumer started, listening to order.placed...\n"; + spdlog::info("Successfully subscribed to order.placed topic"); + spdlog::info("Notification consumer started, listening to order.placed..."); while (!g_shutdown) { std::unique_ptr msg(consumer->consume(1000)); switch (msg->err()) { case RdKafka::ERR_NO_ERROR: { std::string event(static_cast(msg->payload()), msg->len()); - std::cout << "Received event: " << event << "\n"; + spdlog::info("Received event: {}", event); std::string traceparent; if (auto* hdrs = msg->headers()) { @@ -159,7 +159,7 @@ int main() { if (outcome == Outcome::Retry) break; // shutting down: leave the offset uncommitted // Commit only after the side effect, so a crash redelivers rather than loses. if (RdKafka::ErrorCode err = consumer->commitSync(msg.get()); err != RdKafka::ERR_NO_ERROR) { - std::cerr << "Commit failed: " << RdKafka::err2str(err) << "\n"; + spdlog::error("Commit failed: {}", RdKafka::err2str(err)); } break; } @@ -168,7 +168,7 @@ int main() { break; default: // e.g. UNKNOWN_TOPIC_OR_PART before the topic exists; librdkafka retries on its own. - std::cerr << "Kafka error: " << msg->errstr() << "\n"; + spdlog::warn("Kafka error: {}", msg->errstr()); std::this_thread::sleep_for(std::chrono::seconds(1)); } } @@ -179,6 +179,6 @@ int main() { if (g_pg_conn) PQfinish(g_pg_conn); cndp::telemetry::shutdown(); - std::cout << "Notification consumer shutdown complete\n"; + spdlog::info("Notification consumer shutdown complete"); return 0; } diff --git a/examples/05-event-driven/cpp/order-service/src/main.cpp b/examples/05-event-driven/cpp/order-service/src/main.cpp index 73be72f0..cff18c35 100644 --- a/examples/05-event-driven/cpp/order-service/src/main.cpp +++ b/examples/05-event-driven/cpp/order-service/src/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -107,6 +108,8 @@ void init_kafka() { } int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); std::signal(SIGTERM, signal_handler); std::signal(SIGINT, signal_handler); diff --git a/examples/05-event-driven/cpp/shipping-consumer/CMakeLists.txt b/examples/05-event-driven/cpp/shipping-consumer/CMakeLists.txt index 63c9c71c..f9a5dafb 100644 --- a/examples/05-event-driven/cpp/shipping-consumer/CMakeLists.txt +++ b/examples/05-event-driven/cpp/shipping-consumer/CMakeLists.txt @@ -18,8 +18,9 @@ find_package(RdKafka CONFIG REQUIRED) # librdkafka C++ API (rdkafka++) from Con find_package(jsoncpp CONFIG REQUIRED) find_package(PostgreSQL REQUIRED) # libpq from Conan (direct C client) find_package(opentelemetry-cpp CONFIG REQUIRED) +find_package(spdlog CONFIG REQUIRED) find_package(Threads REQUIRED) add_executable(shipping-consumer src/main.cpp) target_include_directories(shipping-consumer PRIVATE src) -target_link_libraries(shipping-consumer PRIVATE RdKafka::rdkafka++ JsonCpp::JsonCpp PostgreSQL::PostgreSQL opentelemetry-cpp::opentelemetry-cpp Threads::Threads) +target_link_libraries(shipping-consumer PRIVATE RdKafka::rdkafka++ JsonCpp::JsonCpp PostgreSQL::PostgreSQL opentelemetry-cpp::opentelemetry-cpp spdlog::spdlog Threads::Threads) diff --git a/examples/05-event-driven/cpp/shipping-consumer/conan.lock b/examples/05-event-driven/cpp/shipping-consumer/conan.lock index cca59aef..05d4815f 100644 --- a/examples/05-event-driven/cpp/shipping-consumer/conan.lock +++ b/examples/05-event-driven/cpp/shipping-consumer/conan.lock @@ -2,6 +2,7 @@ "version": "0.5", "requires": [ "zlib/1.3.2#1cb806da49011867778ffb6ac7190fcb%1777558780.503", + "spdlog/1.17.0#bcbaaf7147bda6ad24ffbd1ac3d7142c%1767636069.964", "protobuf/6.33.5#ca5ff466767b31a1b496ec60247e105c%1785159690.783", "opentelemetry-cpp/1.26.0#000b96632e39f3672f8576bf4febb213%1789030194.301", "openssl/3.6.5#3c1311f37543e7140f33fe5989f315c2%1790692982.113", @@ -11,6 +12,7 @@ "libpq/17.11#6161d3be84f5d2bd657dd778eed017c2%1788252336.346", "libcurl/8.22.0#3599f8564660d38f96af52da40795734%1789660092.861", "jsoncpp/1.9.8#5be5e85394fc94f13f6451e5822ea759%1787912339.522", + "fmt/12.2.0#b445244e6d0151a425e229248cd2bed8%1785754552.386", "abseil/20260107.1#883e95a7be2b767999f64669ac642e5d%1773137897.755" ], "build_requires": [ @@ -37,6 +39,9 @@ ], "nlohmann_json/3.11.3": [ "nlohmann_json/3.12.0" + ], + "fmt/12.1.0": [ + "fmt/12.2.0" ] }, "config_requires": [] diff --git a/examples/05-event-driven/cpp/shipping-consumer/conanfile.py b/examples/05-event-driven/cpp/shipping-consumer/conanfile.py index 05c8c1ca..e221fa32 100644 --- a/examples/05-event-driven/cpp/shipping-consumer/conanfile.py +++ b/examples/05-event-driven/cpp/shipping-consumer/conanfile.py @@ -19,6 +19,8 @@ def requirements(self): self.requires("librdkafka/2.14.2") self.requires("jsoncpp/1.9.8") self.requires("opentelemetry-cpp/1.26.0") + self.requires("spdlog/1.17.0") # opentelemetry-cpp pins nlohmann_json 3.11.3; take the newest release. self.requires("nlohmann_json/3.12.0", override=True) self.requires("lz4/1.10.0", override=True) # librdkafka and libpq pin lz4 1.9.4 + self.requires("fmt/12.2.0", override=True) # spdlog pins fmt 12.1.0 diff --git a/examples/05-event-driven/cpp/shipping-consumer/src/main.cpp b/examples/05-event-driven/cpp/shipping-consumer/src/main.cpp index daa8b81b..307cddbb 100644 --- a/examples/05-event-driven/cpp/shipping-consumer/src/main.cpp +++ b/examples/05-event-driven/cpp/shipping-consumer/src/main.cpp @@ -5,12 +5,12 @@ #include #include +#include #include #include #include #include -#include #include #include #include @@ -32,12 +32,12 @@ void init_pg() { g_pg_conn = PQconnectdb(conninfo); if (PQstatus(g_pg_conn) != CONNECTION_OK) { - std::cerr << "Postgres connection failed: " << PQerrorMessage(g_pg_conn) << "\n"; + spdlog::error("Postgres connection failed: {}", PQerrorMessage(g_pg_conn)); PQfinish(g_pg_conn); g_pg_conn = nullptr; throw std::runtime_error("Postgres connection failed"); } - std::cout << "Connected to Postgres\n"; + spdlog::info("Connected to Postgres"); } enum class Outcome { Done, Skip, Retry }; @@ -51,16 +51,16 @@ Outcome process_event(const std::string& event_json) { std::istringstream stream(event_json); if (!Json::parseFromStream(builder, stream, &root, &errs)) { - std::cerr << "JSON parse error: " << errs << "\n"; + spdlog::warn("JSON parse error: {}", errs); return Outcome::Skip; } if (!root.isObject() || !root.isMember("id")) { - std::cerr << "Missing 'id' field in event\n"; + spdlog::warn("Missing 'id' field in event"); return Outcome::Skip; } std::string order_id = root["id"].asString(); - std::cout << "Processing order: " << order_id << "\n"; + spdlog::info("Processing order: {}", order_id); if (PQstatus(g_pg_conn) != CONNECTION_OK) PQreset(g_pg_conn); @@ -72,9 +72,9 @@ Outcome process_event(const std::string& event_json) { bool ok = PQresultStatus(res) == PGRES_COMMAND_OK; if (!ok) { - std::cerr << "Insert failed: " << PQerrorMessage(g_pg_conn) << "\n"; + spdlog::error("Insert failed: {}", PQerrorMessage(g_pg_conn)); } else { - std::cout << "Shipment created/skipped for order: " << order_id << "\n"; + spdlog::info("Shipment created/skipped for order: {}", order_id); } PQclear(res); return ok ? Outcome::Done : Outcome::Retry; @@ -89,7 +89,7 @@ int main() { try { init_pg(); } catch (const std::exception& e) { - std::cerr << "Initialization failed: " << e.what() << "\n"; + spdlog::error("Initialization failed: {}", e.what()); return 1; } @@ -106,32 +106,32 @@ int main() { {"auto.offset.reset", "earliest"}, {"enable.auto.commit", "false"}}) { if (conf->set(key, value, errstr) != RdKafka::Conf::CONF_OK) { - std::cerr << "Kafka config " << key << ": " << errstr << "\n"; + spdlog::error("Kafka config {}: {}", key, errstr); return 1; } } std::unique_ptr consumer(RdKafka::KafkaConsumer::create(conf.get(), errstr)); if (!consumer) { - std::cerr << "Failed to create consumer: " << errstr << "\n"; + spdlog::error("Failed to create consumer: {}", errstr); return 1; } // subscribe() does not fail when the topic is missing: the consumer keeps polling and // picks the partitions up once the producer has created order.placed. if (RdKafka::ErrorCode err = consumer->subscribe({"order.placed"}); err != RdKafka::ERR_NO_ERROR) { - std::cerr << "Subscribe failed: " << RdKafka::err2str(err) << "\n"; + spdlog::error("Subscribe failed: {}", RdKafka::err2str(err)); return 1; } - std::cout << "Successfully subscribed to order.placed topic\n"; - std::cout << "Shipping consumer started, listening to order.placed...\n"; + spdlog::info("Successfully subscribed to order.placed topic"); + spdlog::info("Shipping consumer started, listening to order.placed..."); while (!g_shutdown) { std::unique_ptr msg(consumer->consume(1000)); switch (msg->err()) { case RdKafka::ERR_NO_ERROR: { std::string event(static_cast(msg->payload()), msg->len()); - std::cout << "Received event: " << event << "\n"; + spdlog::info("Received event: {}", event); std::string traceparent; if (auto* hdrs = msg->headers()) { @@ -159,7 +159,7 @@ int main() { if (outcome == Outcome::Retry) break; // shutting down: leave the offset uncommitted // Commit only after the side effect, so a crash redelivers rather than loses. if (RdKafka::ErrorCode err = consumer->commitSync(msg.get()); err != RdKafka::ERR_NO_ERROR) { - std::cerr << "Commit failed: " << RdKafka::err2str(err) << "\n"; + spdlog::error("Commit failed: {}", RdKafka::err2str(err)); } break; } @@ -168,7 +168,7 @@ int main() { break; default: // e.g. UNKNOWN_TOPIC_OR_PART before the topic exists; librdkafka retries on its own. - std::cerr << "Kafka error: " << msg->errstr() << "\n"; + spdlog::warn("Kafka error: {}", msg->errstr()); std::this_thread::sleep_for(std::chrono::seconds(1)); } } @@ -179,6 +179,6 @@ int main() { if (g_pg_conn) PQfinish(g_pg_conn); cndp::telemetry::shutdown(); - std::cout << "Shipping consumer shutdown complete\n"; + spdlog::info("Shipping consumer shutdown complete"); return 0; } diff --git a/examples/06-stream-processing/cpp/order-service/src/main.cpp b/examples/06-stream-processing/cpp/order-service/src/main.cpp index 318538a1..11039afe 100644 --- a/examples/06-stream-processing/cpp/order-service/src/main.cpp +++ b/examples/06-stream-processing/cpp/order-service/src/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -131,6 +132,8 @@ bool publish_order_event(const std::string& order_json, std::function #include +#include #include #include #include #include -#include #include #include #include @@ -91,9 +91,8 @@ class InventoryServiceImpl final : public inventory::InventoryService::Service { response->set_confirmed(confirmed); response->set_remaining(remaining); - std::cerr << "ReserveStock sku=" << sku << " qty=" << quantity - << " confirmed=" << (confirmed ? "true" : "false") - << " remaining=" << remaining << std::endl; + spdlog::info("ReserveStock sku={} qty={} confirmed={} remaining={}", + sku, quantity, (confirmed ? "true" : "false"), remaining); span->SetAttribute("rpc.system", "grpc"); span->SetAttribute("rpc.service", "inventory.InventoryService"); @@ -130,7 +129,7 @@ int main() { builder.RegisterService(&service); auto server = builder.BuildAndStart(); - std::cerr << "inventory-service started on " << addr << std::endl; + spdlog::info("inventory-service started on {}", addr); while (!g_shutdown) { std::this_thread::sleep_for(std::chrono::milliseconds(500)); diff --git a/examples/11-observability/cpp/notification-consumer/CMakeLists.txt b/examples/11-observability/cpp/notification-consumer/CMakeLists.txt index c2120b86..8ebd5dc0 100644 --- a/examples/11-observability/cpp/notification-consumer/CMakeLists.txt +++ b/examples/11-observability/cpp/notification-consumer/CMakeLists.txt @@ -17,9 +17,10 @@ set(CMAKE_CXX_LINK_EXECUTABLE find_package(RdKafka CONFIG REQUIRED) find_package(PostgreSQL REQUIRED) find_package(opentelemetry-cpp CONFIG REQUIRED) +find_package(spdlog CONFIG REQUIRED) find_package(Threads REQUIRED) add_executable(notification-consumer src/main.cpp) target_include_directories(notification-consumer PRIVATE src) target_link_libraries(notification-consumer PRIVATE - RdKafka::rdkafka++ PostgreSQL::PostgreSQL opentelemetry-cpp::opentelemetry-cpp Threads::Threads) + RdKafka::rdkafka++ PostgreSQL::PostgreSQL opentelemetry-cpp::opentelemetry-cpp spdlog::spdlog Threads::Threads) diff --git a/examples/11-observability/cpp/notification-consumer/conan.lock b/examples/11-observability/cpp/notification-consumer/conan.lock index 0a27b680..d501b21a 100644 --- a/examples/11-observability/cpp/notification-consumer/conan.lock +++ b/examples/11-observability/cpp/notification-consumer/conan.lock @@ -2,6 +2,7 @@ "version": "0.5", "requires": [ "zlib/1.3.2#1cb806da49011867778ffb6ac7190fcb%1777558780.503", + "spdlog/1.17.0#bcbaaf7147bda6ad24ffbd1ac3d7142c%1767636069.964", "protobuf/6.33.5#ca5ff466767b31a1b496ec60247e105c%1785159690.783", "opentelemetry-cpp/1.26.0#000b96632e39f3672f8576bf4febb213%1789030194.301", "openssl/3.6.5#3c1311f37543e7140f33fe5989f315c2%1790692982.113", @@ -10,6 +11,7 @@ "librdkafka/2.14.2#ebe1ce610f423ebe1dbfd52756b98db8%1781073238.939", "libpq/17.11#6161d3be84f5d2bd657dd778eed017c2%1788252336.346", "libcurl/8.22.0#3599f8564660d38f96af52da40795734%1789660092.861", + "fmt/12.2.0#b445244e6d0151a425e229248cd2bed8%1785754552.386", "abseil/20260107.1#883e95a7be2b767999f64669ac642e5d%1773137897.755" ], "build_requires": [ @@ -36,6 +38,9 @@ ], "nlohmann_json/3.11.3": [ "nlohmann_json/3.12.0" + ], + "fmt/12.1.0": [ + "fmt/12.2.0" ] }, "config_requires": [] diff --git a/examples/11-observability/cpp/notification-consumer/conanfile.py b/examples/11-observability/cpp/notification-consumer/conanfile.py index 8191f6c9..f4a08229 100644 --- a/examples/11-observability/cpp/notification-consumer/conanfile.py +++ b/examples/11-observability/cpp/notification-consumer/conanfile.py @@ -20,6 +20,8 @@ def requirements(self): self.requires("librdkafka/2.14.2") self.requires("libpq/17.11") self.requires("opentelemetry-cpp/1.26.0") + self.requires("spdlog/1.17.0") # opentelemetry-cpp pins nlohmann_json 3.11.3; take the newest release. self.requires("nlohmann_json/3.12.0", override=True) self.requires("lz4/1.10.0", override=True) # librdkafka and libpq pin lz4 1.9.4 + self.requires("fmt/12.2.0", override=True) # spdlog pins fmt 12.1.0 diff --git a/examples/11-observability/cpp/notification-consumer/src/main.cpp b/examples/11-observability/cpp/notification-consumer/src/main.cpp index 9445cd04..fb17fad2 100644 --- a/examples/11-observability/cpp/notification-consumer/src/main.cpp +++ b/examples/11-observability/cpp/notification-consumer/src/main.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -15,6 +14,7 @@ #include #include +#include #include "telemetry.hpp" @@ -71,7 +71,7 @@ int main() { const char* env = std::getenv("PG_CONNINFO"); PGconn* pg = PQconnectdb(env ? env : "postgresql://appuser:apppass@postgres:5432/appdb"); if (PQstatus(pg) != CONNECTION_OK) { - std::cerr << "Postgres failed: " << PQerrorMessage(pg) << std::endl; + spdlog::error("Postgres failed: {}", PQerrorMessage(pg)); return 1; } @@ -86,28 +86,28 @@ int main() { conf->set("group.id", "notification-group", err) != RdKafka::Conf::CONF_OK || conf->set("auto.offset.reset", "earliest", err) != RdKafka::Conf::CONF_OK || conf->set("enable.auto.commit", "false", err) != RdKafka::Conf::CONF_OK) { - std::cerr << "Kafka consumer config failed: " << err << std::endl; + spdlog::error("Kafka consumer config failed: {}", err); return 1; } std::unique_ptr consumer(RdKafka::KafkaConsumer::create(conf.get(), err)); if (!consumer) { - std::cerr << "Kafka consumer init failed: " << err << std::endl; + spdlog::error("Kafka consumer init failed: {}", err); return 1; } if (auto rc = consumer->subscribe({"order.placed"}); rc != RdKafka::ERR_NO_ERROR) { - std::cerr << "subscribe failed: " << RdKafka::err2str(rc) << std::endl; + spdlog::error("subscribe failed: {}", RdKafka::err2str(rc)); return 1; } auto tracer = cndp::telemetry::tracer("notification-consumer"); - std::cerr << "notification-consumer started" << std::endl; + spdlog::info("notification-consumer started"); while (!g_shutdown) { std::unique_ptr msg(consumer->consume(1000)); if (msg->err() == RdKafka::ERR__TIMED_OUT || msg->err() == RdKafka::ERR__PARTITION_EOF) continue; if (msg->err() != RdKafka::ERR_NO_ERROR) { // unknown topic before the first order is created, transient broker errors, ... - std::cerr << "consume: " << msg->errstr() << std::endl; + spdlog::warn("consume: {}", msg->errstr()); continue; } @@ -145,15 +145,15 @@ int main() { "INSERT INTO notifications (order_id, channel) VALUES ($1, 'email')", 1, nullptr, params, nullptr, nullptr, 0); if (PQresultStatus(res) == PGRES_COMMAND_OK) { - std::cerr << "notification sent order_id=" << order_id << std::endl; + spdlog::info("notification sent order_id={}", order_id); done = true; } else { const char* state = PQresultErrorField(res, PG_DIAG_SQLSTATE); if (state && std::string(state) == "23505") { - std::cerr << "duplicate skipped order_id=" << order_id << std::endl; + spdlog::info("duplicate skipped order_id={}", order_id); done = true; } else { - std::cerr << "insert failed, retrying: " << PQerrorMessage(pg) << std::endl; + spdlog::warn("insert failed, retrying: {}", PQerrorMessage(pg)); } } PQclear(res); @@ -164,12 +164,12 @@ int main() { // Commit only after the side effect. if (auto rc = consumer->commitSync(msg.get()); rc != RdKafka::ERR_NO_ERROR) - std::cerr << "commit failed: " << RdKafka::err2str(rc) << std::endl; + spdlog::error("commit failed: {}", RdKafka::err2str(rc)); } consumer->close(); PQfinish(pg); cndp::telemetry::shutdown(); - std::cerr << "notification-consumer stopped" << std::endl; + spdlog::info("notification-consumer stopped"); return 0; } diff --git a/examples/16-websockets/cpp/ws-server/src/main.cpp b/examples/16-websockets/cpp/ws-server/src/main.cpp index 5db17a0d..8deccb6b 100644 --- a/examples/16-websockets/cpp/ws-server/src/main.cpp +++ b/examples/16-websockets/cpp/ws-server/src/main.cpp @@ -1,13 +1,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include using namespace drogon; @@ -97,7 +97,7 @@ static void redis_subscriber_loop() { } } } catch (const std::exception& e) { - std::cerr << "Redis subscriber error: " << e.what() << std::endl; + LOG_ERROR << "Redis subscriber error: " << e.what(); } } @@ -135,7 +135,7 @@ class WsCtrl : public WebSocketController { g_clients[client_id] = {conn, 0, {}}; } - std::cerr << "client connected id=" << client_id << " pod=" << g_pod_name << std::endl; + LOG_INFO << "client connected id=" << client_id << " pod=" << g_pod_name; } void handleConnectionClosed(const WebSocketConnectionPtr& conn) override { @@ -144,7 +144,7 @@ class WsCtrl : public WebSocketController { std::lock_guard lock(g_clients_mu); g_clients.erase(*ctx); - std::cerr << "client disconnected id=" << *ctx << " pod=" << g_pod_name << std::endl; + LOG_INFO << "client disconnected id=" << *ctx << " pod=" << g_pod_name; } WS_PATH_LIST_BEGIN @@ -153,6 +153,8 @@ class WsCtrl : public WebSocketController { }; int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); std::signal(SIGTERM, signal_handler); std::signal(SIGINT, signal_handler); @@ -234,7 +236,7 @@ int main() { try { g_redis->publish("ws:broadcast", pub_msg); } catch (const std::exception& e) { - std::cerr << "Redis publish error: " << e.what() << std::endl; + LOG_ERROR << "Redis publish error: " << e.what(); } if (!target.empty()) { @@ -250,7 +252,7 @@ int main() { }, {Post}); - std::cerr << "ws-server started pod=" << g_pod_name << std::endl; + LOG_INFO << "ws-server started pod=" << g_pod_name; app().run(); g_shutdown = true; diff --git a/examples/17-sagas/cpp/saga-orchestrator/src/main.cpp b/examples/17-sagas/cpp/saga-orchestrator/src/main.cpp index 3702f4ad..d275241e 100644 --- a/examples/17-sagas/cpp/saga-orchestrator/src/main.cpp +++ b/examples/17-sagas/cpp/saga-orchestrator/src/main.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -290,6 +291,8 @@ static void resumeRunningSagas() { } int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); const char* dbUrl = std::getenv("DATABASE_URL"); g_connStr = dbUrl ? dbUrl : "postgres://appuser:apppass@localhost:5432/appdb"; diff --git a/examples/18-errors/cpp/order-service/src/main.cpp b/examples/18-errors/cpp/order-service/src/main.cpp index cc487c4f..92d1d733 100644 --- a/examples/18-errors/cpp/order-service/src/main.cpp +++ b/examples/18-errors/cpp/order-service/src/main.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -124,6 +125,8 @@ class OrderController { }; int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); // Initialize gRPC stub std::string inventoryHost = std::getenv("INVENTORY_HOST") ? std::getenv("INVENTORY_HOST") diff --git a/examples/22-l7-routing/cpp/order-service/src/main.cpp b/examples/22-l7-routing/cpp/order-service/src/main.cpp index a9136215..f13476a6 100644 --- a/examples/22-l7-routing/cpp/order-service/src/main.cpp +++ b/examples/22-l7-routing/cpp/order-service/src/main.cpp @@ -1,9 +1,12 @@ #include +#include #include using namespace drogon; int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); std::string version = std::getenv("APP_VERSION") ? std::getenv("APP_VERSION") : "v1"; app().setLogLevel(trantor::Logger::kInfo); diff --git a/examples/22-l7-routing/cpp/router-service/src/main.cpp b/examples/22-l7-routing/cpp/router-service/src/main.cpp index f7db8172..75e320fc 100644 --- a/examples/22-l7-routing/cpp/router-service/src/main.cpp +++ b/examples/22-l7-routing/cpp/router-service/src/main.cpp @@ -1,8 +1,8 @@ #include #include +#include #include #include -#include #include #include #include @@ -48,6 +48,8 @@ static std::string load_script() { } int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); auto rules = std::make_shared(); std::shared_ptr engine; @@ -55,7 +57,7 @@ int main() { // Compiles the script once at startup: a bad rules file stops the service here. engine = std::make_shared(load_script()); } catch (const std::exception& e) { - std::cerr << "invalid rules script: " << e.what() << std::endl; + LOG_ERROR << "invalid rules script: " << e.what(); return 1; } diff --git a/examples/24-monolith-to-microservices/cpp/decorator/src/main.cpp b/examples/24-monolith-to-microservices/cpp/decorator/src/main.cpp index 5527fd64..df3dc5b3 100644 --- a/examples/24-monolith-to-microservices/cpp/decorator/src/main.cpp +++ b/examples/24-monolith-to-microservices/cpp/decorator/src/main.cpp @@ -1,10 +1,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include @@ -33,9 +33,9 @@ class DeliveryLog : public RdKafka::DeliveryReportCb { void dr_cb(RdKafka::Message& message) override { std::unique_ptr pending(static_cast(message.msg_opaque())); if (message.err() != RdKafka::ERR_NO_ERROR) { - std::cerr << "kafka send failed: " << message.errstr() << std::endl; + LOG_ERROR << "kafka send failed: " << message.errstr(); } else if (pending) { - std::cerr << "EVENT order.placed order_id=" << pending->order_id << std::endl; + LOG_INFO << "EVENT order.placed order_id=" << pending->order_id; } if (pending && pending->done) pending->done(); } @@ -110,14 +110,16 @@ static void publish_event(const std::string& order_id, const std::string& order_ msg.data(), msg.size(), nullptr, 0, 0, opaque); if (err == RdKafka::ERR_NO_ERROR) return; delete opaque; - std::cerr << "kafka send failed: " << RdKafka::err2str(err) << std::endl; + LOG_ERROR << "kafka send failed: " << RdKafka::err2str(err); } catch (const std::exception& e) { - std::cerr << "kafka send failed: " << e.what() << std::endl; + LOG_ERROR << "kafka send failed: " << e.what(); } if (done) done(); } int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); auto env_legacy = std::getenv("LEGACY_URL"); g_legacy_url = env_legacy ? env_legacy : "http://legacy:8080"; @@ -134,12 +136,12 @@ int main() { conf->set("acks", "all", errstr) != RdKafka::Conf::CONF_OK || conf->set("message.timeout.ms", "10000", errstr) != RdKafka::Conf::CONF_OK || conf->set("dr_cb", &g_dr_cb, errstr) != RdKafka::Conf::CONF_OK) { - std::cerr << "kafka config: " << errstr << std::endl; + LOG_ERROR << "kafka config: " << errstr; return 1; } g_producer.reset(RdKafka::Producer::create(conf.get(), errstr)); if (!g_producer) { - std::cerr << "kafka producer: " << errstr << std::endl; + LOG_ERROR << "kafka producer: " << errstr; return 1; } g_producer_running = true; @@ -188,7 +190,7 @@ int main() { try { auto cached = g_redis->get(cache_key); if (cached) { - std::cerr << "CACHE_HIT order_id=" << order_id << std::endl; + LOG_INFO << "CACHE_HIT order_id=" << order_id; auto r = HttpResponse::newHttpResponse(); r->setStatusCode(k200OK); r->setContentTypeCode(CT_APPLICATION_JSON); @@ -198,7 +200,7 @@ int main() { } } catch (...) {} - std::cerr << "CACHE_MISS order_id=" << order_id << std::endl; + LOG_INFO << "CACHE_MISS order_id=" << order_id; forward_get(order_id, [order_id, cb = std::move(cb)](std::string result) { diff --git a/examples/24-monolith-to-microservices/cpp/router/src/main.cpp b/examples/24-monolith-to-microservices/cpp/router/src/main.cpp index dd3df80b..c56efdd2 100644 --- a/examples/24-monolith-to-microservices/cpp/router/src/main.cpp +++ b/examples/24-monolith-to-microservices/cpp/router/src/main.cpp @@ -1,7 +1,7 @@ #include +#include #include #include -#include using namespace drogon; @@ -47,6 +47,8 @@ static std::string resolve_upstream(const std::string& tenant) { } int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); auto env_m = std::getenv("MONOLITH_URL"); auto env_n = std::getenv("NEW_SERVICE_URL"); g_service_urls["monolith"] = env_m ? env_m : "http://monolith:8080"; @@ -74,7 +76,7 @@ int main() { tenant = (*body)["tenant"].asString(); } std::string upstream = resolve_upstream(tenant); - std::cerr << "routing tenant=" << tenant << " to " << upstream << std::endl; + LOG_INFO << "routing tenant=" << tenant << " to " << upstream; forward_request(upstream, Post, "/orders", std::string(req->body()), std::move(cb)); }, {Post}); @@ -121,7 +123,7 @@ int main() { g_default_service = (*body)["default"].asString(); } } - std::cerr << "rules updated" << std::endl; + LOG_INFO << "rules updated"; Json::Value r; r["status"] = "updated"; cb(HttpResponse::newHttpJsonResponse(r)); diff --git a/examples/25-caching/cpp/cache-service/src/main.cpp b/examples/25-caching/cpp/cache-service/src/main.cpp index 20e2a306..ff871f8b 100644 --- a/examples/25-caching/cpp/cache-service/src/main.cpp +++ b/examples/25-caching/cpp/cache-service/src/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -271,6 +272,8 @@ void writeback_flusher() { } int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); // Connect to Postgres const char* pg_conninfo = std::getenv("PG_CONNINFO"); if (!pg_conninfo) pg_conninfo = "postgresql://appuser:apppass@localhost:5432/appdb"; diff --git a/examples/26-failure-modes/cpp/backend-service/src/main.cpp b/examples/26-failure-modes/cpp/backend-service/src/main.cpp index a6f058a0..8dd50de9 100644 --- a/examples/26-failure-modes/cpp/backend-service/src/main.cpp +++ b/examples/26-failure-modes/cpp/backend-service/src/main.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -29,6 +30,8 @@ std::mt19937 gen(rd()); std::uniform_int_distribution<> dist(0, 1); int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); // Suppress upload directory warning app().setUploadPath("/tmp"); diff --git a/examples/26-failure-modes/cpp/edge-service/src/main.cpp b/examples/26-failure-modes/cpp/edge-service/src/main.cpp index bba85806..c430ad8d 100644 --- a/examples/26-failure-modes/cpp/edge-service/src/main.cpp +++ b/examples/26-failure-modes/cpp/edge-service/src/main.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -260,6 +261,8 @@ CircuitBreaker g_breaker("backend", 5, 10.0); Bulkhead g_bulkhead(5); int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); // Suppress upload directory warning app().setUploadPath("/tmp"); diff --git a/examples/27-feature-flags/cpp/flag-service/src/main.cpp b/examples/27-feature-flags/cpp/flag-service/src/main.cpp index d0fccac7..0f511b58 100644 --- a/examples/27-feature-flags/cpp/flag-service/src/main.cpp +++ b/examples/27-feature-flags/cpp/flag-service/src/main.cpp @@ -6,6 +6,7 @@ #include #include "schema.pb.h" #include +#include #include #include @@ -65,6 +66,8 @@ class FlagdClient { }; int main() { + // docker logs reads a pipe: line-buffer stdout so LOG_* lines show up as they are written. + std::setvbuf(stdout, nullptr, _IOLBF, 0); std::string flagdHost = std::getenv("FLAGD_HOST") ? std::getenv("FLAGD_HOST") : "flagd"; int flagdPort = std::getenv("FLAGD_PORT") ? std::stoi(std::getenv("FLAGD_PORT")) : 8013; diff --git a/examples/27-feature-flags/go/flag-service/cmd/server/main.go b/examples/27-feature-flags/go/flag-service/cmd/server/main.go index fe80980e..88c1ee59 100644 --- a/examples/27-feature-flags/go/flag-service/cmd/server/main.go +++ b/examples/27-feature-flags/go/flag-service/cmd/server/main.go @@ -70,7 +70,7 @@ func evalCtx(r *http.Request) openfeature.EvaluationContext { if user == "" { user = "anonymous" } - attrs := map[string]interface{}{} + attrs := map[string]any{} if plan := r.Header.Get("X-Plan"); plan != "" { attrs["plan"] = plan } diff --git a/lgtm-presentation/Designing-Cloud-Native-APIs-DotNet.pptx b/lgtm-presentation/Designing-Cloud-Native-APIs-DotNet.pptx index 79298dc1..ec26d584 100644 Binary files a/lgtm-presentation/Designing-Cloud-Native-APIs-DotNet.pptx and b/lgtm-presentation/Designing-Cloud-Native-APIs-DotNet.pptx differ diff --git a/lgtm-presentation/edits/Designing-Cloud-Native-APIs-DotNet.fix7.json b/lgtm-presentation/edits/Designing-Cloud-Native-APIs-DotNet.fix7.json new file mode 100644 index 00000000..017da806 --- /dev/null +++ b/lgtm-presentation/edits/Designing-Cloud-Native-APIs-DotNet.fix7.json @@ -0,0 +1,112 @@ +{ + "ops": [ + { + "op": "replace", + "scope": "notes", + "sldIds": [ + 467 + ], + "expect": 1, + "find": "ASP.NET Core 10 + IHttpClientFactory + IDistributedCache + StackExchange.Redis + Confluent.Kafka + FusionCache", + "repl": "ASP.NET Core 10 + typed HttpClients (IHttpClientFactory) + StackExchange.Redis + Confluent.Kafka", + "_why": "examples/24 dotnet references only Confluent.Kafka and StackExchange.Redis; no FusionCache or IDistributedCache", + "_src": "s13" + }, + { + "op": "replace", + "scope": "notes", + "sldIds": [ + 479 + ], + "expect": 1, + "find": "Code uses IDistributedCache (Microsoft.Extensions.Caching.StackExchangeRedis) for the standard patterns, IConnectionMultiplexer (StackExchange.Redis) for advanced operations, and FusionCache for the read-through / declarative pattern.", + "repl": "Code uses IDistributedCache (Microsoft.Extensions.Caching.StackExchangeRedis) for the standard patterns, IConnectionMultiplexer (StackExchange.Redis) for advanced operations, and HybridCache (Microsoft.Extensions.Caching.Hybrid) for the read-through pattern.", + "_why": "examples/25 reads through HybridCache.GetOrCreateAsync; FusionCache stays only where it adds what HybridCache lacks", + "_src": "s13" + }, + { + "op": "replace", + "scope": "notes", + "sldIds": [ + 487 + ], + "expect": 1, + "find": "Pair with cache-aside or FusionCache.GetOrSetAsync on the read side.", + "repl": "Pair with cache-aside or HybridCache.GetOrCreateAsync on the read side.", + "_why": "examples/25 reads through HybridCache.GetOrCreateAsync; FusionCache stays only where it adds what HybridCache lacks", + "_src": "s13" + }, + { + "op": "replace", + "scope": "slide", + "sldIds": [ + 493 + ], + "expect": 1, + "find": "or FusionCache (built-in stampede protection)", + "repl": "or HybridCache (collapses concurrent misses per Pod)", + "_why": "examples/25 reads through HybridCache.GetOrCreateAsync; FusionCache stays only where it adds what HybridCache lacks", + "_src": "s13" + }, + { + "op": "replace", + "scope": "notes", + "sldIds": [ + 493 + ], + "expect": 1, + "find": "FusionCache solves this out of the box, otherwise use DistributedLock.NET.", + "repl": "HybridCache collapses concurrent misses within each Pod out of the box; across Pods, use DistributedLock.NET.", + "_why": "examples/25 reads through HybridCache.GetOrCreateAsync; FusionCache stays only where it adds what HybridCache lacks", + "_src": "s13" + }, + { + "op": "replace", + "scope": "slide", + "sldIds": [ + 494 + ], + "expect": 1, + "find": "Read-through (FusionCache.GetOrSetAsync) — use when the read path is repetitive and you want declarative caching with built-in stampede protection. Like HybridCache (.NET 9), but with fail-safe and stampede protection built in.", + "repl": "Read-through (HybridCache.GetOrCreateAsync) — use when the read path is repetitive and you want declarative caching with built-in stampede protection. FusionCache adds fail-safe stale fallback and eager refresh.", + "_why": "examples/25 reads through HybridCache.GetOrCreateAsync; FusionCache stays only where it adds what HybridCache lacks; HybridCache does have stampede protection", + "_src": "s13" + }, + { + "op": "replace", + "scope": "slide", + "sldIds": [ + 494 + ], + "expect": 1, + "find": "Write-through (FusionCache.SetAsync or IDistributedCache.SetStringAsync)", + "repl": "Write-through (HybridCache.SetAsync or IDistributedCache.SetStringAsync)", + "_why": "examples/25 reads through HybridCache.GetOrCreateAsync; FusionCache stays only where it adds what HybridCache lacks", + "_src": "s13" + }, + { + "op": "replace", + "scope": "slide", + "sldIds": [ + 494 + ], + "expect": 1, + "find": "Most production ASP.NET Core systems use FusionCache for 95% of cases (it gets you read-through + stampede protection + eager-refresh in one library), with IDistributedCache directly where you need full control.", + "repl": "HybridCache is the in-box default for read-through with stampede protection; FusionCache adds fail-safe, eager refresh and a backplane; use IDistributedCache directly where you need full control.", + "_why": "examples/25 reads through HybridCache.GetOrCreateAsync; FusionCache stays only where it adds what HybridCache lacks; the 95% figure had no source", + "_src": "s13" + }, + { + "op": "replace", + "scope": "notes", + "sldIds": [ + 494 + ], + "expect": 1, + "find": "Decision rules to leave audience with. FusionCache + IDistributedCache is the default modern stack: read-through with stampede protection via GetOrSetAsync, write-through via SetAsync, eager-refresh built in. Drop to IDistributedCache directly when you want full control. Write-around for telemetry. Write-back is the niche extreme-throughput pattern. The bold final line is the take-home: don't pick one pattern as 'the' cache strategy. FusionCache for 95% of cases is the modern default; everything else is a specialization.", + "repl": "Decision rules. HybridCache over the Redis IDistributedCache is the in-box stack: read-through with stampede protection via GetOrCreateAsync, write-through via SetAsync. FusionCache is the alternative when you need fail-safe stale fallback, eager refresh or a backplane for multi-Pod L1 invalidation. Drop to IDistributedCache directly when you want full control. Write-around for telemetry. Write-back is the niche extreme-throughput pattern. The bold final line is the take-home: don't pick one pattern as 'the' cache strategy; choose per read path.", + "_why": "examples/25 reads through HybridCache.GetOrCreateAsync; FusionCache stays only where it adds what HybridCache lacks", + "_src": "s13" + } + ] +} \ No newline at end of file diff --git a/lgtm-presentation/text/Designing-Cloud-Native-APIs-DotNet.md b/lgtm-presentation/text/Designing-Cloud-Native-APIs-DotNet.md index 57e69a28..a3594732 100644 --- a/lgtm-presentation/text/Designing-Cloud-Native-APIs-DotNet.md +++ b/lgtm-presentation/text/Designing-Cloud-Native-APIs-DotNet.md @@ -3162,7 +3162,7 @@ K Patterns that survive the migration with the system still running. -> Appendix K covers the migration patterns. The thesis: you don't decompose a monolith by stopping it and rewriting; you decompose it incrementally, one bounded asset at a time, with the system serving users the whole way through. We'll walk through the monolith as the starting point, modular monoliths as a frequently-correct destination, the strangler-fig family for progressive extraction, content-based routing for fine-grained cutover, and the decorating collaborator for wrapping legacy code you can't touch. Code in this appendix uses ASP.NET Core 10 + IHttpClientFactory + IDistributedCache + StackExchange.Redis + Confluent.Kafka + FusionCache, but the patterns are language-neutral. +> Appendix K covers the migration patterns. The thesis: you don't decompose a monolith by stopping it and rewriting; you decompose it incrementally, one bounded asset at a time, with the system serving users the whole way through. We'll walk through the monolith as the starting point, modular monoliths as a frequently-correct destination, the strangler-fig family for progressive extraction, content-based routing for fine-grained cutover, and the decorating collaborator for wrapping legacy code you can't touch. Code in this appendix uses ASP.NET Core 10 + typed HttpClients (IHttpClientFactory) + StackExchange.Redis + Confluent.Kafka, but the patterns are language-neutral. ## [213] APPENDIX K · MONOLITH · A monolith is a unit of deployment (sldId 468) @@ -3331,7 +3331,7 @@ L Six patterns for keeping a cache useful and your data correct. -> Appendix L is the caching reference. Five reasons to cache and six patterns to do it well. The patterns differ in who reads/writes the cache, when, and who owns the consistency story. We use Redis as the canonical cache because it's the default open-source choice on Kubernetes — same patterns apply to in-memory caches or any KV store. Code uses IDistributedCache (Microsoft.Extensions.Caching.StackExchangeRedis) for the standard patterns, IConnectionMultiplexer (StackExchange.Redis) for advanced operations, and FusionCache for the read-through / declarative pattern. +> Appendix L is the caching reference. Five reasons to cache and six patterns to do it well. The patterns differ in who reads/writes the cache, when, and who owns the consistency story. We use Redis as the canonical cache because it's the default open-source choice on Kubernetes — same patterns apply to in-memory caches or any KV store. Code uses IDistributedCache (Microsoft.Extensions.Caching.StackExchangeRedis) for the standard patterns, IConnectionMultiplexer (StackExchange.Redis) for advanced operations, and HybridCache (Microsoft.Extensions.Caching.Hybrid) for the read-through pattern. ## [225] APPENDIX L · WHY CACHE · Five things a cache earns you (sldId 480) @@ -3473,7 +3473,7 @@ Writes go to the DB only. The next read populates the cache lazily. Good for wri p. 205 -> When data is written far more often than it's read (audit logs, event records, telemetry), caching every write is wasteful: most cached entries expire before being read again. Write-around solves this: write the DB, leave the cache alone. The next reader pays the cache-miss cost and populates the cache. Pros: no cache pollution by write-only data. Cons: the first read after every write is slow (cache miss); reads of recently-written data are slower than under cache-aside. Pair with cache-aside or FusionCache.GetOrSetAsync on the read side. Common use: any 'append-only' or 'mostly-written' workload — audit entries, IoT telemetry. +> When data is written far more often than it's read (audit logs, event records, telemetry), caching every write is wasteful: most cached entries expire before being read again. Write-around solves this: write the DB, leave the cache alone. The next reader pays the cache-miss cost and populates the cache. Pros: no cache pollution by write-only data. Cons: the first read after every write is slow (cache miss); reads of recently-written data are slower than under cache-aside. Pair with cache-aside or HybridCache.GetOrCreateAsync on the read side. Common use: any 'append-only' or 'mostly-written' workload — audit entries, IoT telemetry. ## [233] APPENDIX L · WRITE-AROUND · Write-around in ASP.NET Core (sldId 488) @@ -3608,27 +3608,27 @@ p. 210 - Don't cache by default. Caching adds a consistency story, an invalidation story, and a failure-mode story. If reads are already fast, just don't add a cache — the cheapest cache is no cache. - Don't cache rarely-read data. Caching write-once-read-never data thrashes your cache and gains nothing. Profile read patterns first — OpenTelemetry's cache metrics give you hit/miss ratios per cache. - Don't cache without a TTL. Unbounded caches grow until they evict at random, which gives you the worst type of failure: unpredictable. Always set explicit AbsoluteExpirationRelativeToNow or maxmemory-policy on Redis (allkeys-lru typical). -- Avoid cache stampedes (thundering herd): when a hot key expires and many concurrent ASP.NET Core Pods all miss at once, they all hit the DB. Mitigate with DistributedLock.NET per-key locks, or FusionCache (built-in stampede protection), or refresh-ahead, or jittered TTLs. +- Avoid cache stampedes (thundering herd): when a hot key expires and many concurrent ASP.NET Core Pods all miss at once, they all hit the DB. Mitigate with DistributedLock.NET per-key locks, or HybridCache (collapses concurrent misses per Pod), or refresh-ahead, or jittered TTLs. - Watch for cache aside + write-around without invalidation — the write goes to the DB, but a stale cached value can persist for the full TTL. Always RemoveAsync on writes, or use a short TTL. - Treat the cache as a performance optimisation, never as the source of truth. A Redis outage must mean slower reads, not data loss — always have an EF Core fallback path. Test this by stopping Redis in staging. p. 211 -> Six things that go wrong with caching. The first point is the most important: caching is a complexity tax, only worth paying when reads hurt. The second is the profile-first rule. The third is operational. The fourth is the cache stampede problem — FusionCache solves this out of the box, otherwise use DistributedLock.NET. The fifth is the most common stale-data bug. The bold final line is the architecturally important one: the cache is never the source of truth. If Redis dies, you must serve slower reads, not return errors. Test this by killing Redis in staging. +> Six things that go wrong with caching. The first point is the most important: caching is a complexity tax, only worth paying when reads hurt. The second is the profile-first rule. The third is operational. The fourth is the cache stampede problem — HybridCache collapses concurrent misses within each Pod out of the box; across Pods, use DistributedLock.NET. The fifth is the most common stale-data bug. The bold final line is the architecturally important one: the cache is never the source of truth. If Redis dies, you must serve slower reads, not return errors. Test this by killing Redis in staging. ## [239] APPENDIX L · DECISIONS · Choosing the right caching pattern (sldId 494) - Cache-aside — the default. Use when you want explicit control and reads dominate writes. -- Read-through (FusionCache.GetOrSetAsync) — use when the read path is repetitive and you want declarative caching with built-in stampede protection. Like HybridCache (.NET 9), but with fail-safe and stampede protection built in. -- Write-through (FusionCache.SetAsync or IDistributedCache.SetStringAsync) — use when zero stale-read risk after a write matters more than write latency. +- Read-through (HybridCache.GetOrCreateAsync) — use when the read path is repetitive and you want declarative caching with built-in stampede protection. FusionCache adds fail-safe stale fallback and eager refresh. +- Write-through (HybridCache.SetAsync or IDistributedCache.SetStringAsync) — use when zero stale-read risk after a write matters more than write latency. - Write-around — use when writes far outnumber re-reads. Avoids cache pollution by write-once data. - Write-back (BackgroundService + dirty-set) — use only when extreme write throughput is the constraint and eventual durability is acceptable. - Refresh-ahead (FusionCache eager-refresh, or BackgroundService) — use when a small set of hot keys serves most traffic and miss latency is unacceptable. -- Most production ASP.NET Core systems use FusionCache for 95% of cases (it gets you read-through + stampede protection + eager-refresh in one library), with IDistributedCache directly where you need full control. Mix patterns; don't pick one as the rule. +- HybridCache is the in-box default for read-through with stampede protection; FusionCache adds fail-safe, eager refresh and a backplane; use IDistributedCache directly where you need full control. Mix patterns; don't pick one as the rule. p. 212 -> Decision rules to leave audience with. FusionCache + IDistributedCache is the default modern stack: read-through with stampede protection via GetOrSetAsync, write-through via SetAsync, eager-refresh built in. Drop to IDistributedCache directly when you want full control. Write-around for telemetry. Write-back is the niche extreme-throughput pattern. The bold final line is the take-home: don't pick one pattern as 'the' cache strategy. FusionCache for 95% of cases is the modern default; everything else is a specialization. +> Decision rules. HybridCache over the Redis IDistributedCache is the in-box stack: read-through with stampede protection via GetOrCreateAsync, write-through via SetAsync. FusionCache is the alternative when you need fail-safe stale fallback, eager refresh or a backplane for multi-Pod L1 invalidation. Drop to IDistributedCache directly when you want full control. Write-around for telemetry. Write-back is the niche extreme-throughput pattern. The bold final line is the take-home: don't pick one pattern as 'the' cache strategy; choose per read path. ## [240] Appendix M · Failure modes (sldId 495)