Documentation Index
Fetch the complete documentation index at: https://www.aidonow.com/llms.txt
Use this file to discover all available pages before exploring further.
Executive Summary
Multi-tenant SaaS platforms face a systemic risk when AWS SDK clients are instantiated ad hoc across service boundaries: the absence of structural isolation guarantees creates conditions for cross-tenant data exposure that unit tests cannot reliably detect. This analysis documents the design and implementation of a scope-aware AWS client factory pattern for a Rust-based SaaS platform, wherein four distinct operational scopes — platform, tenant, capsule, and operator — are encoded directly into the SDK client type hierarchy. The factory pattern, derived through systematic analysis of existing architectural decision records (ADRs), reduced per-crate boilerplate by approximately 600 lines and enforced 100 percent ADR compliance through the type system rather than documentation. A critical operational gap — the absence of credential caching for cross-account STS operations — required human intervention informed by production experience with AWS assume-role latency characteristics. Organizations building multi-tenant infrastructure should treat architectural decision records as primary inputs to AI-assisted design, encode isolation boundaries in API types rather than naming conventions, and layer performance optimizations only after structural correctness is established.Key Findings
- Ad hoc AWS client instantiation across 9 Rust crates and 16 SDKs produced no compile-time barrier to cross-tenant data access, representing a structural security deficit rather than a procedural one.
- A four-scope client hierarchy (platform, tenant, capsule, operator) derived directly from ADR-0010 enforced isolation automatically at the SDK level, requiring zero developer discipline for compliance.
- AI-assisted pattern extraction from structured ADR documentation reduced the design-through-migration cycle from an estimated two weeks to three days — a 78 percent reduction in elapsed time.
- AI-generated implementations consistently omit operationally derived optimizations: the initial design lacked STS credential caching, introducing 200–500 ms latency per cross-account operation until corrected by a human reviewer.
- Each crate migration eliminated approximately 600 lines of client-creation boilerplate and replaced inconsistent error handling with compiler-enforced patterns.
- 39 integration tests covering 9 AWS services and 4 scope types reached zero production defects across the Phase 1 migration of 3 crates.
1. Problem Definition: Structural Isolation Gaps in Distributed AWS Client Management
By January 2026, the subject platform had grown to encompass 9 Rust crates consuming 16 distinct AWS SDKs. Client instantiation followed no consistent pattern: DynamoDB clients appeared inside authentication handlers, S3 clients inside upload endpoints, and SQS clients distributed across application layers without coordination. This arrangement produced three compounding deficiencies:- No credential governance. Each instantiation site called
aws_config::load_from_env()independently, precluding centralized credential rotation or assumption policies. - No scope enforcement. Clients carried no concept of the operational boundary — platform, tenant, or environment — within which they were permitted to operate.
- No structural isolation. Table names were hardcoded strings, making cross-tenant access a matter of developer oversight rather than type-system enforcement.
2. Methodology: ADR-Driven AI Pattern Extraction
The design process deliberately avoided prescriptive prompting. Rather than instructing an AI evaluator agent to “build an AWS client factory,” the engagement presented ADR-0010 — the platform’s documented isolation boundary specification — and posed the architectural question: given these constraints, how should AWS clients be managed? This distinction is consequential. Prescriptive prompting produces implementations of the requester’s mental model. Constraint-driven prompting allows the model to surface structural patterns the human may not have articulated. The evaluator agent identified four distinct operational scopes encoded implicitly in ADR-0010:| Scope | Purpose | Isolation Boundary | Credential Model |
|---|---|---|---|
| Platform | Cross-tenant infrastructure (metrics, logs, platform config) | None — shared by all tenants | Environment credentials |
| Tenant | Customer-specific resources | Tenant ID prefix | Environment credentials (IAM role: planned) |
| Capsule | SDLC environment resources (dev/staging/prod) | Capsule code prefix + partition key validation | Environment credentials |
| Operator | Cross-account AWS Organizations operations | Cross-account IAM assumption | STS AssumeRole |
3. The Four-Scope Client Architecture
3.1 Platform Clients
Platform clients operate on shared infrastructure with no tenant-specific prefixing.Platform (No Isolation)
3.2 Tenant Clients
Tenant clients scope all resource access to a specific customer boundary, with an architectural path for future cross-account IAM role assumption.Tenant (Tenant Boundary)
3.3 Capsule Clients
The capsule client represents the most architecturally significant finding. ADR-0010 required SDLC environment isolation — development data must not appear in production query results. The evaluator agent proposed automatic table prefixing derived from the capsule code, enforced at compile time.Capsule (SDLC Isolation)
3.4 Operator Clients
Operator clients support cross-account AWS Organizations operations and are the only client type requiring STS assume-role credential chains.Operator (Cross-Account)
4. Operational Deficiency: Credential Caching Gap
The initial AI-generated implementation exposed a material operational deficiency.5. Migration Approach and Measured Impact
Phase 1 migrated 3 crates — auth, crm, and catalog — to validate the pattern before broader rollout. Before (auth crate):| Crate | Files Changed | Boilerplate Removed |
|---|---|---|
| auth | 14 | ~600 lines |
| crm | 22 | ~600 lines |
| catalog | 8 | ~600 lines |
6. Comparative Analysis: Pre- and Post-Implementation State
| Dimension | Before Factory Pattern | After Factory Pattern |
|---|---|---|
| Isolation enforcement | Developer discipline (naming conventions) | Compile-time type system |
| Credential management | 9+ independent instantiation sites | Single factory, centralized |
| ADR compliance | Unverifiable at build time | 100% enforced by API surface |
| Cross-tenant risk | Structural — cannot be reviewed away | Eliminated by design |
| Boilerplate per crate | ~600 lines | ~0 lines (factory call) |
| Time to migrate additional crate | ~3 days (estimated) | ~2–4 hours (with migration guide) |
| Operational caching | None | Moka, 55-min TTL, AWS-aligned |
7. AI Collaboration Profile
The engagement surface for AI assistance was well-defined and productive within its scope. Specific observations merit documentation for practitioners evaluating similar workflows.AI Capability Boundary: AI evaluator agents extract structural patterns from structured documents (ADRs, specifications) with high fidelity. They do not infer operational characteristics — latency profiles, credential TTLs, cache sizing — from documentation alone. Organizations should budget for human review of all performance-sensitive infrastructure generated by AI agents.
- Scope identification from ADR-0010 (zero human prompting required)
- Client type hierarchy design
- Table naming convention implementation
- Test generation (39 integration tests, 2,364 lines in 3 days)
- STS credential caching (operational knowledge)
- LocalStack endpoint configuration (environment-specific knowledge)
- Credential TTL alignment with AWS session limits (operational knowledge)
8. Recommendations
- Encode isolation boundaries in type systems, not naming conventions. Any multi-tenant architecture that relies on developer discipline to maintain naming conventions is structurally insecure. Compile-time enforcement through scope-typed client hierarchies eliminates the defect class entirely.
- Treat architectural decision records as primary AI design inputs. Before engaging AI assistance for infrastructure design, produce structured ADRs that specify isolation boundaries, scope rules, and naming conventions. AI agents derive more architecturally coherent solutions from constraint documents than from feature requests.
- Stage AI-generated implementations through human operational review before production. Mandate review by practitioners with relevant AWS operational experience for any infrastructure involving credential management, cross-account access, or performance-sensitive paths. Document findings as ADR amendments.
- Migrate incrementally, validating test parity at each step. Phase 1 migration of 3 crates took 2 days with the multi-agent workflow (Evaluator plans, Builder executes per crate, Verifier confirms test passage). Attempting broader rollout without per-crate verification increases defect introduction risk.
-
Centralize factory instantiation as an application-layer dependency. A single
AwsClientFactoryinstance injected via dependency provides a natural seam for testing (LocalStack substitution), credential rotation, and observability instrumentation.
9. Implementation Metrics Summary
| Metric | Value |
|---|---|
| Crates in scope | 9 |
| AWS SDKs managed | 9 services |
| Infrastructure added | 2,364 lines |
| Integration tests generated | 39 |
| Production defects post-migration | 0 |
| Phase 1 crates migrated | 3 |
| Estimated time without AI assistance | ~2 weeks |
| Actual elapsed time | 3 days |
| Elapsed time reduction | 78% |
| Boilerplate removed per crate | ~600 lines |
10. Conclusion and Forward-Looking Assessment
The scope-based client factory pattern resolves a structural security and maintainability deficit that is endemic to ad hoc multi-tenant AWS client management. By encoding isolation boundaries in the type system rather than naming conventions, organizations eliminate an entire defect class that conventional code review cannot reliably prevent. The combination of ADR-driven design and AI-assisted implementation accelerates delivery while preserving architectural coherence — provided that human operational expertise reviews AI-generated output before production deployment. As AI-assisted infrastructure design matures, the practitioner’s role will increasingly shift toward constraint specification (ADRs, architecture principles) and operational review, rather than initial implementation. Organizations that invest in structured ADRs today position themselves to extract disproportionate productivity from AI design assistance as these workflows become standard practice.Resources and Further Reading
- AWS SDK for Rust Documentation
- Multi-Tenancy on AWS
- Related article: Documentation as Architecture (ADRs)
Next in This Series
Week 6: How configuration governance middleware eliminated 100% of manual config lookups using the same ADR-driven approach.Week 6: Configuration Governance
The middleware pattern that made configuration hierarchical and automatic
Discussion
Share Your Experience
Have you built multi-tenant infrastructure? How do you enforce isolation boundaries?Connect on LinkedIn
Disclaimer: This content represents my personal learning journey using AI for a personal project. It does not represent my employer’s views, technologies, or approaches.All code examples are generic patterns or pseudocode for educational purposes.