Enterprise State Architecture
Enterprise State Architecture covers multi-tenant SaaS ownership, Redux Toolkit versus TanStack Query, tenant switches, and feature boundaries.
Course: React — State Management Lesson: 13
Learning objectives
Design state boundaries for a large React application, distinguish client and server state, define domain ownership, and establish conventions for scalable teams.
Enterprise state is not one store
A mature SaaS application may contain authentication, workspace selection, permissions, product catalogue, orders, dashboards, forms, filters, and notifications. These values do not share the same lifecycle or ownership.
A practical architecture separates:
- Component-local UI state.
- Feature-level client state.
- Cross-feature client state.
- Remote server state.
- URL state.
- Persistent preferences where required.
Example architecture
Application|+-- Router / URL state|+-- Global client state| +-- Auth/session metadata| +-- Workspace selection| +-- Preferences| +-- Notifications|+-- Feature state| +-- Checkout workflow| +-- Dashboard filters| +-- Product editor|+-- Server-state layer+-- Customers+-- Orders+-- Inventory+-- Reports
The architecture may use Context, Redux Toolkit, Zustand, and TanStack Query selectively. Do not adopt every library simply because it is available.
Define ownership rules
For every state value, document:
- Who owns it?
- Who can update it?
- Which components consume it?
- Does it come from the server?
- Does it need to survive refresh?
- What invalidates it?
- Is it scoped to a user, tenant, or feature?
These questions prevent duplicate sources of truth and unclear ownership.
Multi-tenant concerns
In a multi-tenant SaaS, tenant identity must be reflected in API authorization and often in cache identity. On workspace switch, the application must avoid displaying data from the previous tenant. The backend must enforce tenant isolation; a frontend store or query key is not a security boundary.
Feature-oriented organization
Keep domain state and operations close to their feature:
features/orders/components/hooks/services/state/tests/inventory/components/hooks/services/state/tests/shared/api/auth/ui/
A feature can use local state, a small store, or query hooks according to its needs. Shared infrastructure should remain genuinely shared.
State contracts and team conventions
Define naming conventions, query-key factories, error shapes, cache invalidation rules, persistence policy, and testing expectations. A consistent architecture reduces onboarding cost and prevents each team from solving the same state problem differently.
Observability and resilience
Capture request failures, latency, mutation outcomes, and key user workflows. Avoid logging sensitive payloads. Provide fallback states for unavailable services and ensure session or tenant transitions clear or isolate sensitive client data.
Common mistakes
- One global store for every kind of state.
- Multiple competing sources of truth.
- Tenant-unaware cache keys.
- Feature logic spread across unrelated shared folders.
- No documented invalidation strategy.
- Treating client-side permissions as enforcement.
Best practices
Use explicit ownership, feature boundaries, server-state tooling for remote data, consistent cache policies, tenant-aware lifecycle handling, and architecture tests where valuable.
Interview questions & answers
Interview preparation
5 questions grouped by difficulty — expand any card for a model answer and follow-up probe.
Beginner
1How would you design state architecture for a multi-tenant SaaS?
BeginnerModel answer
Separate local UI, shared client, and server state; scope caches by tenant/user; clear on switch/logout; enforce authorization on the server.
2How do feature boundaries help large teams?
BeginnerModel answer
They keep ownership clear—feature stores/hooks/services—so teams change one area without creating a global state tangle.
Intermediate
3How do you decide between Redux Toolkit and TanStack Query?
IntermediateModel answer
Use TanStack Query for remote server state caching.
Use Redux Toolkit for complex shared client workflows that are not primarily server cache.
4How would you prevent duplicate sources of truth?
IntermediateModel answer
Assign one owner per data concern, derive instead of duplicating, and avoid mirroring server cache into ad-hoc global stores.
Advanced
5What should happen to cached data on tenant switch?
AdvancedModel answer
Clear or isolate tenant-scoped caches so the previous tenant's data cannot leak into the next session.
Practice
Design state architecture for a SaaS platform with billing, orders, inventory, analytics, and user administration. Document the owner, tool, persistence, cache key, and invalidation policy for each important value.