How do you handle state synchronization between the frontend client and the backend database?
Mention HTTP polling, WebSockets, Server-Sent Events, Optimistic UI updates, and cache invalidation strategies (React Query / SWR).
"To sync state, I use React Query on the frontend for automatic caching, background refetching, and query invalidation. For real-time updates, like chat or notification feeds, I establish a WebSocket connection. I also implement optimistic UI updates, rendering the updated state instantly in the UI before server confirmation, rolling it back only if the API call fails."