Skip to content

Commit f88facf

Browse files
authored
feat: add snapshot checkpoint management pattern (#459)
1 parent a5bfa66 commit f88facf

28 files changed

Lines changed: 1286 additions & 11 deletions

File tree

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,11 @@ var cachedRemoteProxy = Proxy<int, string>.Create(id => remoteProxy.Execute(id))
473473
---
474474

475475
## Patterns Table
476-
PatternKit currently tracks 112 production-readiness patterns. Each catalog pattern is represented in tests, documentation, real-world examples, IoC integration, and the BenchmarkDotNet coverage matrix.
476+
PatternKit currently tracks 113 production-readiness patterns. Each catalog pattern is represented in tests, documentation, real-world examples, IoC integration, and the BenchmarkDotNet coverage matrix.
477477

478478
| Category | Count | Patterns |
479479
| --- | ---: | --- |
480-
| Application Architecture | 24 | Activity Tracker, Aggregate Root, Anti-Corruption Layer, Audit Log, Bounded Context, Context Map, CQRS, Data Mapper, Domain Event, Domain Service, Event Sourcing, Feature Toggle, Identity Map, Manual Task Gate, Materialized View, Repository, Service Layer, Specification, Table Data Gateway, Timeout Manager, Transaction Script, Unit of Work, Value Object, Workflow Orchestration |
480+
| Application Architecture | 25 | Activity Tracker, Aggregate Root, Anti-Corruption Layer, Audit Log, Bounded Context, Context Map, CQRS, Data Mapper, Domain Event, Domain Service, Event Sourcing, Feature Toggle, Identity Map, Manual Task Gate, Materialized View, Repository, Service Layer, Snapshot / Checkpoint Management, Specification, Table Data Gateway, Timeout Manager, Transaction Script, Unit of Work, Value Object, Workflow Orchestration |
481481
| Behavioral | 11 | Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, Visitor |
482482
| Cloud Architecture | 20 | Ambassador, Backends for Frontends, Bulkhead, Cache-Aside, Cache Stampede Protection, Circuit Breaker, External Configuration Store, Gateway Aggregation, Gateway Routing, Health Endpoint Monitoring, Leader Election, Priority Queue, Queue-Based Load Leveling, Rate Limiting, Read-Through Cache, Retry, Scheduler Agent Supervisor, Sidecar, Strangler Fig, Write-Through Cache |
483483
| Creational | 5 | Abstract Factory, Builder, Factory Method, Prototype, Singleton |
@@ -501,6 +501,8 @@ BenchmarkDotNet guidance is documented in [docs/guides/benchmarks.md](docs/guide
501501
| Manual Task Gate | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
502502
| Workflow Orchestration | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
503503
| Workflow Orchestration | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
504+
| Snapshot / Checkpoint Management | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
505+
| Snapshot / Checkpoint Management | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
504506
| Timeout Manager | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
505507
| Timeout Manager | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
506508
| Aggregate Root | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using BenchmarkDotNet.Attributes;
2+
using PatternKit.Application.SnapshotCheckpoints;
3+
using PatternKit.Examples.SnapshotCheckpointDemo;
4+
5+
namespace PatternKit.Benchmarks.Application;
6+
7+
[BenchmarkCategory("ApplicationArchitecture", "SnapshotCheckpointManagement")]
8+
public class SnapshotCheckpointManagementBenchmarks
9+
{
10+
[Benchmark(Baseline = true, Description = "Fluent: create snapshot checkpoint manager")]
11+
[BenchmarkCategory("Fluent", "Construction")]
12+
public SnapshotCheckpointManager<string, OrderReplaySnapshot> Fluent_CreateSnapshotCheckpointManager()
13+
=> OrderReplaySnapshotCheckpointPolicies.CreateFluentManager();
14+
15+
[Benchmark(Description = "Generated: create snapshot checkpoint manager")]
16+
[BenchmarkCategory("Generated", "Construction")]
17+
public SnapshotCheckpointManager<string, OrderReplaySnapshot> Generated_CreateSnapshotCheckpointManager()
18+
=> GeneratedOrderReplayCheckpoints.CreateManager();
19+
20+
[Benchmark(Description = "Fluent: replay order with snapshot checkpoint")]
21+
[BenchmarkCategory("Fluent", "Execution")]
22+
public OrderReplaySummary Fluent_ReplayOrderWithSnapshotCheckpoint()
23+
=> OrderReplaySnapshotCheckpointDemo.RunFluentAsync().AsTask().GetAwaiter().GetResult();
24+
25+
[Benchmark(Description = "Generated: replay order with snapshot checkpoint")]
26+
[BenchmarkCategory("Generated", "Execution")]
27+
public OrderReplaySummary Generated_ReplayOrderWithSnapshotCheckpoint()
28+
=> OrderReplaySnapshotCheckpointDemo.RunGeneratedAsync().AsTask().GetAwaiter().GetResult();
29+
}

docs/examples/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Welcome! This section collects small, focused demos that show **how to compose b
1919
* **Messaging backplane facade** for host-style setup, typed request/reply, and publish/subscribe over an application-owned transport boundary.
2020
* **Production-readiness catalog** for DI, generic host, and ASP.NET Core diagnostics that maps every documented example to its source, TinyBDD tests, docs page, integration surfaces, and production checks.
2121
* **Workflow orchestration** for explicit ordered fulfillment steps with retries, conditional gates, compensation, and execution history.
22+
* **Snapshot / checkpoint management** for resumable event stream replay and projection rebuilds.
2223

2324
## Demos in this section
2425

@@ -43,6 +44,9 @@ Welcome! This section collects small, focused demos that show **how to compose b
4344
* **Fulfillment Workflow Orchestration**
4445
A Generic Host importable fulfillment workflow with fluent and source-generated routes for inventory reservation, fraud review, payment capture, retries, warehouse release, and compensation. See [Fulfillment Workflow Orchestration](fulfillment-workflow-orchestration.md).
4546

47+
* **Order Replay Snapshot Checkpoint Management**
48+
A Generic Host importable replay service with fluent and source-generated checkpoint manager routes for event-sourced order rebuilds. See [Order Replay Snapshot Checkpoint Management](order-replay-snapshot-checkpoint.md).
49+
4650
* **Minimal Web Request Router**
4751
A tiny "API gateway" that separates **first-match middleware** (side effects/logging/auth) from **first-match routes** and **content negotiation**. A crisp example of Strategy patterns in an HTTP-ish setting.
4852

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Order Replay Snapshot Checkpoint Management
2+
3+
This example models an event-sourced order replay service that stores compact checkpoints after rebuilding order state. A replay can resume from a usable checkpoint and only apply later events.
4+
5+
The fluent path builds the checkpoint manager directly:
6+
7+
```csharp
8+
var manager = OrderReplaySnapshotCheckpointPolicies.CreateFluentManager();
9+
```
10+
11+
The generated path uses a source-generated factory:
12+
13+
```csharp
14+
var manager = GeneratedOrderReplayCheckpoints.CreateManager();
15+
```
16+
17+
The example is importable through standard dependency injection:
18+
19+
```csharp
20+
services.AddOrderReplaySnapshotCheckpointDemo();
21+
```
22+
23+
`OrderReplayService` composes an `IEventStore<OrderReplayEvent, string>` with `SnapshotCheckpointManager<string, OrderReplaySnapshot>`. Production applications can replace the in-memory event store with their own storage while keeping the checkpoint manager construction, stale checkpoint handling, and replay tests intact.

docs/examples/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
- name: Fulfillment Workflow Orchestration
1717
href: fulfillment-workflow-orchestration.md
1818

19+
- name: Order Replay Snapshot Checkpoint Management
20+
href: order-replay-snapshot-checkpoint.md
21+
1922
- name: Auth & Logging with `ActionChain<HttpRequest>`
2023
href: auth-logging-chain.md
2124

docs/generators/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ PatternKit includes a Roslyn incremental generator package (`PatternKit.Generato
6464
| [**Activity Tracker**](activity-tracker.md) | Active-work tracker gates for loading and readiness workflows | `[GenerateActivityTracker]` |
6565
| [**Manual Task Gate**](manual-task-gate.md) | Human approval gates for workflow pauses and manual decisions | `[GenerateManualTaskGate]` |
6666
| [**Workflow Orchestration**](workflow-orchestration.md) | Ordered workflow factories from annotated step methods | `[WorkflowOrchestration]` |
67+
| [**Snapshot / Checkpoint Management**](snapshot-checkpoint-management.md) | Replay checkpoint manager factories for resumable processors | `[GenerateSnapshotCheckpointManager]` |
6768
| [**Timeout Manager**](timeout-manager.md) | Deadline registry for expiring pending workflow work | `[GenerateTimeoutManager]` |
6869
| [**Audit Log**](audit-log.md) | Append-only audit log factories from key selectors | `[GenerateAuditLog]` |
6970
| [**Unit of Work**](unit-of-work.md) | Ordered commit and rollback units | `[GenerateUnitOfWork]` |
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Snapshot / Checkpoint Management Generator
2+
3+
The Snapshot / Checkpoint Management generator creates a strongly typed factory for a `SnapshotCheckpointManager<TKey, TSnapshot>` from a partial host type.
4+
5+
```csharp
6+
using PatternKit.Generators.SnapshotCheckpoints;
7+
8+
[GenerateSnapshotCheckpointManager(
9+
typeof(string),
10+
typeof(OrderReplaySnapshot),
11+
FactoryMethodName = "CreateManager",
12+
ManagerName = "order-replay-checkpoints")]
13+
public static partial class GeneratedOrderReplayCheckpoints;
14+
```
15+
16+
Generated output:
17+
18+
```csharp
19+
SnapshotCheckpointManager<string, OrderReplaySnapshot> manager =
20+
GeneratedOrderReplayCheckpoints.CreateManager();
21+
```
22+
23+
Use the fluent manager when runtime configuration needs a custom comparer, clock, or stale write policy. Use the generated factory when a module wants a discoverable, allocation-light construction path with the manager name and types fixed at compile time.
24+
25+
## Diagnostics
26+
27+
- `PKSCP001`: the snapshot checkpoint manager host type must be partial.
28+
- `PKSCP002`: `FactoryMethodName` and `ManagerName` must be non-empty.

docs/generators/toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,9 @@
276276
- name: Timeout Manager
277277
href: timeout-manager.md
278278

279+
- name: Snapshot / Checkpoint Management
280+
href: snapshot-checkpoint-management.md
281+
279282
- name: Strategy
280283
href: strategy.md
281284

docs/guides/benchmark-results.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ The latest measured timings below were captured on Windows 11, Intel Core i9-149
2121
| Manual Task Gate | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
2222
| Workflow Orchestration | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
2323
| Workflow Orchestration | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
24+
| Snapshot / Checkpoint Management | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
25+
| Snapshot / Checkpoint Management | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
2426
| Timeout Manager | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
2527
| Timeout Manager | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
2628
| Aggregate Root | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
@@ -244,19 +246,19 @@ The latest measured timings below were captured on Windows 11, Intel Core i9-149
244246

245247
## Coverage Matrix Summary
246248

247-
The coverage matrix currently publishes 112 catalog patterns and 448 pattern route results. Each pattern has four BenchmarkDotNet routes: fluent construction, fluent execution, source-generated construction, and source-generated execution. The reusable hosting integration matrix publishes 9 reusable hosting integration route results for package-level `IServiceCollection` registrations.
249+
The coverage matrix currently publishes 113 catalog patterns and 452 pattern route results. Each pattern has four BenchmarkDotNet routes: fluent construction, fluent execution, source-generated construction, and source-generated execution. The reusable hosting integration matrix publishes 9 reusable hosting integration route results for package-level `IServiceCollection` registrations.
248250

249251
| Category | Patterns | Published route results |
250252
| --- | ---: | ---: |
251-
| Application Architecture | 24 | 96 |
253+
| Application Architecture | 25 | 100 |
252254
| Behavioral | 11 | 44 |
253255
| Cloud Architecture | 20 | 80 |
254256
| Creational | 5 | 20 |
255257
| Enterprise Integration | 41 | 164 |
256258
| Messaging Reliability | 3 | 12 |
257259
| Structural | 7 | 28 |
258260

259-
The generator matrix currently publishes 106 generator source route results.
261+
The generator matrix currently publishes 107 generator source route results.
260262

261263
## Hosting Integration Matrix Results
262264

@@ -279,6 +281,7 @@ The generator matrix currently publishes 106 generator source route results.
279281
| Application Architecture | Activity Tracker | Covered | Covered | Covered | Covered |
280282
| Application Architecture | Manual Task Gate | Covered | Covered | Covered | Covered |
281283
| Application Architecture | Workflow Orchestration | Covered | Covered | Covered | Covered |
284+
| Application Architecture | Snapshot / Checkpoint Management | Covered | Covered | Covered | Covered |
282285
| Application Architecture | Timeout Manager | Covered | Covered | Covered | Covered |
283286
| Application Architecture | Aggregate Root | Covered | Covered | Covered | Covered |
284287
| Application Architecture | Anti-Corruption Layer | Covered | Covered | Covered | Covered |
@@ -396,6 +399,7 @@ The generator matrix currently publishes 106 generator source route results.
396399
| TimeoutManagerGenerator | `src/PatternKit.Generators/Timeouts/TimeoutManagerGenerator.cs` | Covered |
397400
| ManualTaskGateGenerator | `src/PatternKit.Generators/ManualTaskGates/ManualTaskGateGenerator.cs` | Covered |
398401
| WorkflowOrchestrationGenerator | `src/PatternKit.Generators/WorkflowOrchestration/WorkflowOrchestrationGenerator.cs` | Covered |
402+
| SnapshotCheckpointManagerGenerator | `src/PatternKit.Generators/SnapshotCheckpoints/SnapshotCheckpointManagerGenerator.cs` | Covered |
399403
| AggregateCommandHandlerGenerator | `src/PatternKit.Generators/Aggregates/AggregateCommandHandlerGenerator.cs` | Covered |
400404
| AdapterGenerator | `src/PatternKit.Generators/Adapter/AdapterGenerator.cs` | Covered |
401405
| AmbassadorGenerator | `src/PatternKit.Generators/Ambassador/AmbassadorGenerator.cs` | Covered |

docs/guides/benchmarks.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ The following numbers were captured on Windows 11, Intel Core i9-14900K, .NET SD
3838
| Manual Task Gate | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
3939
| Workflow Orchestration | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
4040
| Workflow Orchestration | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
41+
| Snapshot / Checkpoint Management | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
42+
| Snapshot / Checkpoint Management | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
4143
| Timeout Manager | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
4244
| Timeout Manager | Execution | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |
4345
| Aggregate Root | Construction | Pending | Pending | Pending | Pending | Covered by the BenchmarkDotNet matrix; publish measured values after the next benchmark refresh. |

0 commit comments

Comments
 (0)