How a Robot Vacuum App Fixed Map Jank, Cache Staleness, and P2P Lag
Any app that composites a live device feed with cloud-managed configuration hits the same class of bugs: cache staleness after user edits, real-time data clobbering static state, and slow peer-to-peer connections blocking the UI. The three-tier data model here—local cache for instant paint, cloud as the source of truth, P2P as the final correction—is a transferable pattern for IoT, robotics, and smart-home apps.
The device detail page for TanGe robot vacuums suffered from slow map loads, conflicting loading indicators, and stale caches that caused the map to jump or fail to refresh after a user switched or deleted maps. Path data persisted across app restarts produced jarring trajectory jumps, while forbidden zones appeared noticeably later than the map itself. A rewrite of the caching layer now treats the cloud as the authoritative source, refreshes caches through a single unified entry point after every map management action, and distinguishes between stable configuration data (forbidden zones, which are cached) and strongly real-time data (paths, which are not).
During cleaning, map management data is blocked from overwriting the live map to prevent visual jumps. Quick-mapping now polls the cloud up to three times instead of firing a single delayed request, and forbidden-zone cache keys bind to both device and map IDs to survive multi-map setups. The team also removed a 5-second request throttle that dropped map and path data when users rapidly toggled between the device list and the detail page.
The broader P2P connection strategy layers local cache, cloud map management data, and real-time device reports so the UI never waits on a slow peer-to-peer link. Pre-connection, short-term keep-alive, a connection state machine, and LAN-first relay fallback are all on the table, though the SDK's three-device pre-connect limit constrains the first option.
Distinguishing configuration data from real-time data is the core design decision that makes or breaks an IoT cache layer; forbidden zones are stable enough to cache, paths are not.
Unifying cache invalidation into a single method call is a low-cost change that eliminates an entire class of stale-data bugs caused by scattered cache writes.
Blocking map management data from updating the live map during cleaning is a state-aware guard that many apps miss, leading to the classic 'map jumps while the robot is running' complaint.
The quick-mapping polling fix highlights a common IoT trap: treating a command ACK as proof that the cloud side-effect has completed.
Removing the 5-second request throttle trades a bit of network load for correctness; the original throttle was a premature optimization that caused visible data loss.
Binding forbidden-zone cache keys to mapId is forward-looking even if the current device treats zones as global, because multi-map support inevitably arrives.
The P2P pre-connect limit of three devices is a hard SDK constraint that forces a trade-off between connection speed and device resource pressure.