Skip to content
June 1, 2026
  • Linkedin
  • Twitter
  • Facebook
  • Youtube

Daily CyberSecurity

Zero-hour alerts. Unmatched analysis.

Primary Menu
  • Home
  • CVE Watchtower
  • Cyber Criminals
  • Data Leak
  • Linux
  • Malware
  • Vulnerability
  • Submit Press Release
  • Vulnerability Report
Light/Dark Button
  • Home
  • Technique
  • State Management Architecture. Part 2. From RTK Query to Zustand
  • Technique

State Management Architecture. Part 2. From RTK Query to Zustand

Dan Agbo January 19, 2025 7 minutes read
CVE-2024-31070 & CVE-2024-36491

This article is the second part of a series of publications by Hiveon’s leading frontend engineer Anton An about the best frameworks for state-management. You can read about the evolution of state-management, traditional Redux and RTK Toolkit, which develops its approaches, in the first part of the article.

In state-management, traditional Redux is considered obsolete. Modern alternatives include RTK Query and Zustand, and frameworks can be used together to complement each other in your project.

RTK Query

RTK Query focuses on synchronizing application state with server data, making it an excellent tool for API-driven projects. It provides automatic caching to minimize redundant requests, request deduplication, and built-in polling intervals for periodic data updates—features that streamline server state management.

However, effective cache management is critical. Incorrectly configured cache invalidation or tag relationships can result in stale data or unnecessary re-fetching, impacting performance. For instance, subtle changes in input parameters might trigger excessive re-renders if tags are not carefully defined. Thorough planning and testing are required to leverage RTK Query’s full potential.


// missionApi.js (API Slice)
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';

// Define the mission API slice
export const missionApi = createApi({
reducerPath: 'missionApi',
baseQuery: fetchBaseQuery({ baseUrl: 'https://api.space-mission.example.com/' }), // Hypothetical API
tagTypes: ['Missions', 'Resources'], // Tags for cache invalidation
endpoints: (builder) => ({
// Fetch all active missions
getMissions: builder.query({
query: () => 'missions',
providesTags: ['Missions'], // Tag for caching missions
}),
// Fetch resource levels (oxygen, fuel)
getResources: builder.query({
query: () => 'resources',
providesTags: ['Resources'], // Tag for caching resources
// Polling every 30 seconds to simulate real-time updates
pollingInterval: 30000,
}),
// Update mission status (e.g., mark as completed)
updateMissionStatus: builder.mutation({
query: ({ id, status }) => ({
url: `missions/${id}`,
method: 'PATCH',
body: { status },
}),
invalidatesTags: ['Missions'], // Invalidate mission cache on update
}),
}),
});

// Export hooks for usage in components
export const {
useGetMissionsQuery,
useGetResourcesQuery,
useUpdateMissionStatusMutation,
} = missionApi;

// store.js (Store Configuration)
import { configureStore } from '@reduxjs/toolkit';
import { missionApi } from './missionApi';

// Configure the store with RTK Query reducer
const store = configureStore({
reducer: {
[missionApi.reducerPath]: missionApi.reducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(missionApi.middleware),
});

export default store;

// MissionDashboard.js (Component)
import React from 'react';
import {
useGetMissionsQuery,
useGetResourcesQuery,
useUpdateMissionStatusMutation,
} from './missionApi';

export function MissionDashboard() {
// Fetch missions with automatic caching
const {
data: missions,
error: missionsError,
isLoading: missionsLoading,
} = useGetMissionsQuery();

// Fetch resources with polling
const {
data: resources,
error: resourcesError,
isLoading: resourcesLoading,
} = useGetResourcesQuery();

// Mutation to update mission status
const [updateMissionStatus] = useUpdateMissionStatusMutation();

if (missionsLoading || resourcesLoading) return <p>Loading mission data...</p>;
if (missionsError || resourcesError)
return <p>Error fetching data: {missionsError?.message || resourcesError?.message}</p>;

return (
<div>
<h1>Space Mission Control Dashboard</h1>

{/* Missions Section */}
<section>
<h2>Active Missions</h2>
<ul>
{missions.map((mission) => (
<li key={mission.id}>
{mission.destination} - {mission.status}
{mission.status === 'Active' && (
<button
onClick={() =>
updateMissionStatus({ id: mission.id, status: 'Completed' })
}
>
Mark as Completed
</button>
)}
</li>
))}
</ul>
</section>

{/* Resources Section */}
<section>
<h2>Resource Levels (Updated every 30s)</h2>
<p>Oxygen: {resources.oxygen}%</p>
<p>Fuel: {resources.fuel}%</p>
</section>
</div>
);
}

// App.js (Main App)
import React from 'react';
import { Provider } from 'react-redux';
import store from './store';
import { MissionDashboard } from './MissionDashboard';

function App() {
return (
<Provider store={store}>
<MissionDashboard />
</Provider>
);
}

export default App;
  • missionApi: Defines endpoints for fetching missions (getMissions), resources (getResources), and updating mission status (updateMissionStatus).
  • Caching: providesTags ensures data is cached under ‘Missions’ and ‘Resources’. The updateMissionStatus mutation invalidates the ‘Missions’ tag, triggering a refetch.
  • Polling: getResources uses a 30-second pollingInterval to simulate real-time resource monitoring.

This tool is best suited for applications where server data is a primary concern, as it excels at managing the client-side cache of that data, handling the fetching, synchronization, and updates automatically. For purely local state needs, Redux Toolkit alone may suffice.

RTK Query Overview:

  • Primary Role: Managing server state in data-intensive applications.
  • Advantages: Efficient caching, deduplication, and polling support.
  • Potential Issues: Cache configuration demands precision to avoid inconsistencies.

Next, we turn to Zustand, a contrasting approach that prioritizes simplicity over structure.

Zustand

Zustand offers a lightweight alternative to the Redux ecosystem, appealing to developers who need global state management without extensive overhead. Its minimal API enables rapid state setup—ideal for small libraries or performance-sensitive components where a full Redux implementation would be excessive.

This simplicity comes with trade-offs. Zustand lacks the rigid structure of Redux, requiring disciplined practices to maintain consistency in larger applications. Additionally, it offers no native support for complex asynchronous workflows, leaving developers to implement custom solutions as needed.

For projects prioritizing speed and minimalism, Zustand is highly effective. Its flexibility makes it a compelling choice when the complexity of Redux outweighs its benefits.

When it comes to syntax, Zustand is impressively more laconic than the same RTK library when writing code that handles passing states to components. Here’s an example of Zustand code implementing the astronaut status management similar to our Traditional Redux example:

// missionStore.js (Zustand Store)
import { create } from 'zustand';

// Create a Zustand store for mission data
const useMissionStore = create((set) => ({
astronauts: [
{ id: 1, name: 'Alex Carter', status: 'In Space' },
{ id: 2, name: 'Sam Rivera', status: 'On Ground' },
],
toggleAstronautStatus: (id) =>
set((state) => ({
astronauts: state.astronauts.map((astronaut) =>
astronaut.id === id
? {
...astronaut,
status: astronaut.status === 'In Space' ? 'On Ground' : 'In Space',
}
: astronaut
),
})),
}));

export default useMissionStore;

// MissionControl.js (Component with Zustand)
import React from 'react';
import useMissionStore from './missionStore';

export function MissionControl() {
// Access state and actions directly from the store
const astronauts = useMissionStore((state) => state.astronauts);
const toggleAstronautStatus = useMissionStore((state) => state.toggleAstronautStatus);

return (
<div>
<h1>Space Mission Control (Zustand)</h1>
<h2>Astronaut Status</h2>
<ul>
{astronauts.map((astronaut) => (
<li key={astronaut.id}>
{astronaut.name} - {astronaut.status}
<button onClick={() => toggleAstronautStatus(astronaut.id)}>
Toggle Status
</button>
</li>
))}
</ul>
</div>
);
}

// App.js (Main App with Zustand)
import React from 'react';
import { MissionControl } from './MissionControl';

function App() {
return <MissionControl />;
}

export default App;
  • Setup: A single file (missionStore.js) with create defines the store. No reducers or middleware needed.
  • Usage: The useMissionStore hook provides direct access to state (astronauts) and actions (toggleAstronautStatus) without extra boilerplate.
  • Theme: Manages astronaut statuses (e.g., “In Space” or “On Ground”), fitting the mission control theme.
  • Pros: Lightweight, minimal API, no provider wrapper required.
  • Trade-offs: No built-in structure for complex async flows (e.g., API calls would need custom logic).

As you can see Zustand is ideal for simple state needs in our space mission context. However, as noted, its lack of rigid structure means developers must enforce discipline in larger apps, and async tasks (e.g., fetching astronaut data) would need manual handling—unlike RTK’s ecosystem support.

 

Zustand Essentials:

  • Best Scenarios: Simple global state or performance-critical components.
  • Benefits: Lightweight design and efficient updates.
  • Limitations: Requires careful management in large projects; async support is minimal: asynchronous logic is often handled by placing async functions directly within the store or by using Zustand’s middleware support if needed.

To clarify these distinctions, let’s compare the options directly.

Comparative Analysis

The table below consolidates key attributes—performance, scalability, learning curve, ecosystem support, and challenges—based on practical observations. It aims to assist in identifying the most suitable tool for your project.

Feature Traditional Redux Redux Toolkit RTK Query Zustand
Performance Solid when optimized, but requires manual effort. Enhanced by streamlined processes and less boilerplate. Strong for server state with proper caching. Highly efficient for localized updates.
Scalability Effective for large apps, though setup is cumbersome. Scales well with a structured yet efficient approach. Excellent for API-heavy projects. Suitable for smaller to mid-sized apps with discipline.
Learning Curve High due to extensive configuration requirements. Moderate; builds on Redux with simplified patterns. Moderate, with added complexity from caching. Low, thanks to its straightforward API.
Ecosystem Extensive and mature, with broad middleware support. Robust, leveraging Redux’s ecosystem with modern tools. Well-integrated within Redux frameworks. Smaller but expanding steadily.
Challenges Verbose code; unoptimized selectors hurt performance. Abstraction may obscure mechanics. Cache mismanagement can disrupt data flow. Lack of structure risks inconsistency.
Ideal Use Complex apps needing precise control. Modern, structured state management. Server-data synchronization. Lightweight, performance-focused needs.

Building on this comparison, consider how these tools might work together.

Combining Approaches

In some cases, a hybrid strategy can maximize the strengths of multiple tools. Pairing Redux Toolkit with RTK Query, for instance, provides robust UI state management alongside optimized server data handling within the Redux ecosystem. Adding Zustand for specific, performance-critical components introduces localized efficiency without redundant complexity.

Integration poses challenges, however. While Redux Toolkit and RTK Query align seamlessly, Zustand’s distinct paradigm requires careful consideration for synchronization. While React’s useSyncExternalStore primitive provides a foundation for integrating external stores, connecting disparate state managers like Redux and Zustand smoothly often relies on well-designed application architecture or potentially specific adapter libraries. Without deliberate design, this can lead to inefficiencies, such as redundant updates. Clear boundaries and testing are essential to ensure a cohesive architecture.

Finally, let’s distill this into a practical framework for decision-making.

Checklist: How to choose the right framework for your project situation?

The following considerations can guide your choice of state management solution, tailored to your project’s needs:

  • How big is your project going to be? Large, intricate applications often benefit from the structure provided by the Redux ecosystem (typically via Redux Toolkit); smaller efforts might lean toward Zustand.
  • What states will need to be managed? Focus on UI state suggests RTK or Zustand; server synchronization points to RTK Query.
  • What kind of performance are you willing to put up with? Evaluate memoization and caching needs; Zustand excels in lightweight contexts.
  • What is the expertise of the development team? Familiarity with Redux supports RTK adoption; simpler tools suit less experienced teams.
  • What integrations are you planning to do? Combining tools requires strategic state synchronization to avoid overhead.

These questions provide a starting point for aligning your choice with project demands and team capabilities.

Conclusion

Choosing a state management solution requires balancing complexity, performance, and practicality. Traditional Redux offers unmatched control for intricate applications, though its verbosity can be a hurdle. Redux Toolkit refines this approach, delivering efficiency and clarity for modern needs. RTK Query excels in server-state scenarios, provided cache management is precise. Zustand, meanwhile, provides a nimble alternative for simpler or performance-driven requirements.

A combined approach can leverage these strengths, but demands thoughtful integration. By assessing your project’s scope, state needs, and team expertise—guided by the framework above—you can select a strategy that ensures scalability and maintainability tailored to your goals.

Share this article:

Facebook Post LinkedIn Telegram

No related posts.

Search

Translation

CVE WATCHTOWER
🚨

Receive alerts for vulnerabilities being exploited in the wild.

⚡

Get notified instantly when a Proof of Concept (PoC) exploit is published.

🔍

Access critical info on vulnerabilities even when marked as "RESERVED".

🧠

Insights powered by decades of expertise and global intelligence sources.

🎯

Customize alerts with up to 10 keywords for your specific tech stack.

📊

Export the raw CVE database for SIEM integration and reporting.

Upgrade Package

🔴 Live Critical Threats

  • CVE-2026-48879CVSS 9.8
    Incorrect Privilege Assignment vulnerability in Sergey AIWU allows Privilege Escalation. This issue...
  • CVE-2026-48866CVSS 9.6
    Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') vulnerability...
  • CVE-2026-42682CVSS 9.1
    Missing Authorization vulnerability in Tomdever wpForo Forum allows Exploiting Incorrectly Configured Access...
  • CVE-2026-42680CVSS 9.8
    Incorrect Privilege Assignment vulnerability in Wasiliy Strecker / ContestGallery developer Contest Gallery...
  • CVE-2026-47413CVSS 9.6
    ## Summary **Type:** Privilege escalation / cross-tenant member injection. The `POST /workspaces/{workspace_id}/members`...
  • CVE-2026-47428CVSS 9.6
    ## Summary Vitest browser mode served `/__vitest_test__/` with the `otelCarrier` query parameter...
  • CVE-2026-7858CVSS 9.8
    A Deserialization of Untrusted Data vulnerability affecting Teamwork Cloud from No Magic...
  • CVE-2026-48188CVSS 9.1
    An improper Input Validation vulnerability in OTRS or ((OTRS)) Community Edition database layer...
  • CVE-2026-10187CVSS 9.8
    A vulnerability was detected in Totolink N300RH 6.1c.1353_B20190305. Affected by this issue...
  • CVE-2018-25412CVSS 9.8
    Delta Sql 1.8.2 contains an arbitrary file upload vulnerability that allows unauthenticated...
Powered by CVE WATCHTOWER

Recent Zero-Day Vulnerabilities

  • Exploited in the Wild: Critical OWA Spoofing Flaw (CVE-2026-42897) Hits On-Premises Exchange Servers
  • Exploited in the Wild: Maximum CVSS 10 SD-WAN Flaw (CVE-2026-20182) Grants Admin Control
  • Exploited in the Wild: Critical 9.8 CVSS RCE Hits Canon GUARDIANWALL MailSuite
  • Exploit Code Released: Public PoC Dumps for Windows BitLocker Bypass and SYSTEM Elevation Zero-Days
  • Exploited in the Wild: “Dirty Frag” Linux Vulnerability Grants Instant Root Access
  • Under Active Attack: Ivanti EPMM Zero-Day Exploited in the Wild via Harvested Admin Credentials
Our Websites
  • Penetration Testing Tools
  • The Daily Information Technology
  • Daily CyberSecurity

    • About SecurityOnline.info
    • Advertise with us
    • Announcement
    • Contact
    • Contributor Register
    • Login
    • About SecurityOnline.info
    • Advertise on SecurityOnline.info
    • Contact Us

    When you purchase through links on our site, we may earn an affiliate commission. Here’s how it works

    • Disclaimer
    • Privacy Policy
    • DMCA NOTICE
    • Linkedin
    • Twitter
    • Facebook
    • Youtube
    Copyright Daily CyberSecurity © All rights reserved.