|
| 1 | +# ADR-030: Governance Redis Request Storage and Query Strategy |
| 2 | + |
| 3 | +## Tag |
| 4 | +#adr_030 |
| 5 | + |
| 6 | +## Status |
| 7 | +Accepted |
| 8 | + |
| 9 | +## Date |
| 10 | +2026-06-25 |
| 11 | + |
| 12 | +## Scope |
| 13 | +ModularityKit.Mutator.Governance.Redis |
| 14 | + |
| 15 | +## Context |
| 16 | + |
| 17 | +Once the Redis provider package exists, it still needs a concrete storage and read strategy. |
| 18 | + |
| 19 | +Governed request data has two competing needs: |
| 20 | + |
| 21 | +- writes should stay simple and durable |
| 22 | +- queue-oriented operational reads should avoid a full scan of every request whenever possible |
| 23 | + |
| 24 | +The provider also needs to preserve governance runtime semantics such as: |
| 25 | + |
| 26 | +- optimistic concurrency by request revision |
| 27 | +- storage-agnostic request query filtering |
| 28 | +- approval and decision projections built from parent request state |
| 29 | + |
| 30 | +Without an explicit strategy, the Redis provider could drift into ad hoc key naming, inconsistent indexing, or duplicated query behavior that no longer matches the governance abstractions. |
| 31 | + |
| 32 | +## Decision |
| 33 | + |
| 34 | +The Redis provider stores one serialized request document per request and maintains a small set of Redis secondary indexes for common request-oriented reads. |
| 35 | + |
| 36 | +Storage shape: |
| 37 | + |
| 38 | +- one request JSON document per `MutationRequest` |
| 39 | +- one revision key per request for optimistic concurrency |
| 40 | +- set indexes for: |
| 41 | + - all request ids |
| 42 | + - requests by `StateId` |
| 43 | + - requests by `MutationRequestStatus` |
| 44 | + - all pending requests |
| 45 | + - pending requests by `PendingMutationReason` |
| 46 | + |
| 47 | +Query shape: |
| 48 | + |
| 49 | +- Redis index selection happens first through candidate-planning internals |
| 50 | +- matching request documents are then loaded in bulk |
| 51 | +- final filtering is applied through governance query evaluators, not Redis-specific ad hoc logic |
| 52 | +- approval views and decision views are projected from loaded parent requests after candidate selection |
| 53 | + |
| 54 | +Internal provider structure should remain decomposed: |
| 55 | + |
| 56 | +- candidate planning and execution |
| 57 | +- document key creation and payload loading |
| 58 | +- document materialization |
| 59 | +- read-side query orchestration |
| 60 | + |
| 61 | +## Design Rationale |
| 62 | + |
| 63 | +- Document-per-request storage maps naturally to the governance request model. |
| 64 | +- Separate revision keys give a simple optimistic concurrency mechanism in Redis transactions. |
| 65 | +- A small set of explicit secondary indexes improves the common queue and status reads without forcing the provider into a large custom indexing subsystem. |
| 66 | +- Reusing governance evaluators keeps provider behavior aligned with in-memory and future providers. |
| 67 | +- Internal decomposition makes Redis-specific read mechanics easier to evolve without turning one class into the entire provider. |
| 68 | + |
| 69 | +## Consequences |
| 70 | + |
| 71 | +### Positive |
| 72 | + |
| 73 | +- Request writes stay simple and explicit. |
| 74 | +- Common operational views such as pending queues and state/status slices can be narrowed through Redis sets. |
| 75 | +- Query semantics remain aligned with governance abstractions because the final filter pass is evaluator-driven. |
| 76 | +- Internal provider responsibilities are easier to test and evolve independently. |
| 77 | + |
| 78 | +### Negative |
| 79 | + |
| 80 | +- Broad ad hoc queries still fall back to loading candidate request documents and filtering in memory. |
| 81 | +- Index maintenance increases write-path complexity compared to pure document storage. |
| 82 | +- Additional indexes may be needed later for higher-volume provider scenarios. |
| 83 | + |
| 84 | +## Related ADRs |
| 85 | + |
| 86 | +- ADR-022: Governance Request Decisions and Storage |
| 87 | +- ADR-026: Governance Request Query API |
| 88 | +- ADR-029: Governance Redis Provider Package |
0 commit comments