How Instagram Direct engineers... Note

How Instagram Direct engineers built AI-native UI architecture with Jetpack Compose and reduced token cost per agent session by 33%

The Instagram Direct team undertook a significant modernization of their Android UI by adopting Jetpack Compose. This migration went beyond a simple UI rewrite; they aimed to build an AI-native codebase from the ground up. The primary motivation was to address technical debt and engineering overhead associated with a highly optimized legacy View system. Jetpack Compose's declarative nature was chosen to make the UI code more predictable and easier for AI models to understand.A gradual migration strategy was crucial due to the massive scale of Instagram Direct, handling billions of messages daily. Embedding Compose within the existing View hierarchy was considered an interim step, but a full transition was preferred to avoid subtle bugs and performance issues caused by mixing UI paradigms. The team focused on creating clear architectural boundaries to enhance AI's ability to produce high-quality code.By adhering to AI-friendly principles, such as minimizing custom context dependencies and enforcing architectural boundaries, the team ensured better AI results. They developed a structured migration process that involved writing all Compose code with AI assistance, followed by polishing and testing. This approach allowed for rapid development without disrupting ongoing feature releases.The results demonstrated substantial improvements: the UI code was reduced by 50%, engineer-agent exchanges decreased by 32%, and AI execution time dropped by 35%. Token costs for AI tasks also saw a 33% reduction when using Compose compared to Views. The new Compose-based UI showed greater resilience to code risk compared to the legacy View system. This collaborative effort between Meta and Google not only modernized Instagram Direct but also contributed to the broader Android developer ecosystem by optimizing Compose itself. The team successfully met and even exceeded the high-performance bar of the legacy UI, ensuring a seamless user experience.