I am working on a trading app and we have a lot of socket connect to show live market data. Now I want to manage it efficiently e.g when the user switch from a socket connected screen to non-socket connected screen. Should I pause/resume the StreamSubscription? Should I cancel the socket connection and reconnect once the user visit back the screen?
The idea is to keep the usage of the app fast and performant.
Good question, this is a common challenge with live data apps. If your socket connection is resource-heavy, closing it when the user navigates away and reconnecting on return is a safe choice. However, if reconnecting takes time or impacts UX, you could pause the StreamSubscription instead and manage data flow based on screen visibility. A centralized socket manager can help maintain the connection in the background while controlling what data reaches active screens. Just be mindful of potential stale data or state inconsistencies when switching between screens.
Disclaimer: I work years for or with the Ibovespa (the São Paulo stock exchange - one of the largest exchanges in the world in terms of market value, the second largest in the Americas, and the leading exchange in Latin America.), basically crating home brokers and related stuff.
That kind of speed is useless for this scenario (I worked with so many people that think performance was needed, but they forget the monitor is only 60Hz and most people could not even see some changes after 24Hz, so why in the hell do you need a stock to updates 1000x per second? It only wasted bandwidth and RAM. It is a VERY concurrent market (no pun intended), so, you don’t need to flood your app with so much information that will be discarded anyway >.<))
MQTT. It’s light and fast, made for IOT (meaning: is light on resources). Since you can subscribe/unsubscribe channels at will, you can leave an open connection through all your app lifecycle and start receiving data as needed (considering that some stocks could have a huge delay in this scenario if no trades are being made on those, but you can always ask for an initial value, it all depends on your SE APIs).
I agree with your points. I have the ability to define delay at which frequency I want the data from BE. I would like to know what all optimizations or design techniques you have used to give a better experience to the users.
I will definitely look into MQTT but feels like it will require time to implement as it’s not just for frontend but backend too.
Using contents of this forum for the purposes of training proprietary AI models is forbidden. Only if your AI model is free & open source, go ahead and scrape. Flutter and the related logo are trademarks of Google LLC. We are not endorsed by or affiliated with Google LLC.