I’m building a subscription app with React frontend and Python backend. I use Stripe webhooks to update customer information in my database when payment events happen.
The issue is that some Stripe events happen without user interaction (like failed renewals or trial expirations). When these events trigger my webhook and update the database, the user’s browser doesn’t know about the changes. If someone is logged in during these updates, their displayed information becomes outdated.
I’m looking for the best approach to handle this situation. Here are some options I considered:
WebSocket connections - Push updates from webhook to connected clients, but users might not always be online
Periodic API calls - Call user info endpoint every few minutes, but seems wasteful
Check on each request - Fetch latest user data with every API call, but doubles request volume
Response headers - Include user data in all API responses and update state when different, but adds complexity
What’s the recommended pattern for keeping frontend user state synchronized with webhook-driven backend updates? I want something efficient that doesn’t overload the server.