TECH_COMPARISON

NgRx vs NGXS: Redux Pattern vs State Class Model for Angular

NgRx brings Redux patterns to Angular with RxJS integration; NGXS offers a simpler class-based state model with less ceremony.

7 min readUpdated Jan 15, 2025
ngrxngxsangularstate-managementrxjs

Overview

NgRx and NGXS are the two most popular state management libraries for Angular applications, and both are strongly influenced by Redux's unidirectional data flow philosophy. NgRx (Angular Reactive Extensions) is the official, Angular-affiliated library that applies Redux patterns using RxJS throughout — actions, reducers, and selectors, with effects as Observables for side effects. NGXS takes inspiration from Redux but replaces the functional reducer model with a class-based state model using decorators, reducing some of NgRx's ceremony.

NgRx is more widely adopted and has closer ties to the Angular core team. NGXS appeals to developers who find NgRx's boilerplate excessive and prefer Angular's object-oriented, decorator-based idioms.

Key Technical Differences

NgRx's architecture follows Redux closely. Actions are created with createAction, reducers with createReducer and on, selectors with createSelector. Effects use the RxJS operator pipeline to listen for dispatched actions, perform async operations, and dispatch result actions. This deep RxJS integration means effects can leverage the full power of RxJS operators — switchMap for cancellation, combineLatest for combined state, debounceTime for input handling — but requires RxJS expertise.

NGXS uses a class-based model. State is defined as a class decorated with @State, with @Action methods that handle incoming actions and modify state directly (using a patching mechanism). Actions are also classes with a static type property. This feels more natural to Angular developers accustomed to services and dependency injection, and the class-based structure reduces some of NgRx's file proliferation (separate files for actions, reducer, effects, selectors).

NgRx's @ngrx/component-store is a complementary library for managing local component state in a reactive way — similar to NGXS's global store model but scoped to a component's lifetime. This allows consistent reactive state patterns at both the global and local level within an NgRx application.

Performance & Scale

Both libraries integrate with Redux DevTools, enabling time-travel debugging and state inspection in development. Performance at scale is comparable — both use Angular's change detection efficiently through Observable selectors. NgRx's memoized selectors from createSelector cache derived state and only recompute when dependencies change, providing efficient rendering with large state trees.

When to Choose Each

Choose NgRx for large Angular applications where team familiarity with Redux and RxJS is high, or where the depth of reactive programming integration in effects is needed. The larger community and Angular team affiliation also provide confidence in long-term maintenance.

Choose NGXS for applications where NgRx's boilerplate is a genuine burden and your team prefers the class-based decorator model. For medium-complexity Angular apps where full NgRx is overhead, NGXS provides a reasonable middle ground.

Bottom Line

NgRx wins on community size, RxJS depth, and long-term Angular alignment. NGXS wins on reduced boilerplate and a more accessible learning curve for Angular developers unfamiliar with Redux. For large enterprise Angular applications, NgRx is the safer choice; for smaller teams or applications, NGXS may provide better developer productivity.

GO DEEPER

Master this topic in our 12-week cohort

Our Advanced System Design cohort covers this and 11 other deep-dive topics with live sessions, assignments, and expert feedback.