Data Fetching Strategies
The Tuturuuu platform uses a layered approach to data fetching, choosing the right strategy based on use case, caching requirements, and user experience needs.Strategy Preference Order
Choose the earliest applicable strategy:- Pure Server Component (RSC) - Read-only, cacheable, SEO-critical data
- Server Action - Mutations returning updated state to RSC
- RSC + Client Hydration - When background refresh needed
- React Query (Client-Side) - Interactive, rapidly changing state
- Realtime Subscriptions - Live updates materially improve UX
1. Pure Server Component (RSC)
When to Use
✅ Best For:- Initial page load data
- SEO-critical content
- Rarely changing data
- Read-only operations
- Database queries that don’t need real-time updates
- Interactive forms
- Frequent updates
- Client-side state
- Real-time data
Implementation
Caching Strategy
Loading States
Error Handling
2. Server Actions
When to Use
✅ Best For:- Form submissions
- Mutations with server-side validation
- Operations requiring auth checks
- Redirects after mutations
- Progressive enhancement
- Read operations (use RSC instead)
- Complex client-side state management
- Real-time updates
Implementation
Client Usage
3. RSC + Client Hydration
When to Use
✅ Best For:- Initial server render with client updates
- Data that changes frequently
- Combining SEO with interactivity
- Background refresh patterns
Implementation
4. React Query (Client-Side)
When to Use
✅ Best For:- Interactive dashboards
- Rapidly changing data
- Complex client-side state
- Optimistic updates
- Automatic background refetching
- SEO-critical content
- Initial page load (prefer RSC)
Implementation with tRPC
Query Key Conventions
Use stable array query keys:Optimistic Updates
Cache Invalidation
5. Realtime Subscriptions
When to Use
✅ Best For:- Collaborative features
- Chat applications
- Live dashboards
- Multiplayer features
- Notification systems
- Infrequent updates
- Static content
- SEO-critical data
Implementation
React Query Guidelines
Query Configuration
Prefetching
Parallel Queries
Dependent Queries
Decision Matrix
Use Case | Strategy | Why |
---|---|---|
Blog posts | RSC | SEO, rarely changes |
Task list (initial load) | RSC | Fast initial render |
Create task form | Server Action | Mutation, redirect |
Dashboard metrics | React Query | Frequent updates |
Real-time chat | Realtime Subscription | Collaboration |
Task toggle | React Query (optimistic) | Interactive, instant feedback |
User profile (view) | RSC | Rarely changes |
User profile (edit) | Server Action | Mutation with validation |
Workspace members | RSC + hydration | SEO + background refresh |
Live notifications | Realtime Subscription | Real-time updates critical |
Best Practices
✅ DO
-
Start with RSC
-
Use specific query keys
-
Set appropriate staleTime
-
Implement optimistic updates for better UX
-
Invalidate narrowly
❌ DON’T
-
Don’t use client fetching for SEO content
-
Don’t skip staleTime
-
Don’t invalidate globally
-
Don’t use Realtime for infrequent updates