Under the hood: Improving messages

Visit the post for more.

Adam Wolff
6 min readintermediate
--
View Original

Overview

The article discusses the improvements made to Facebook's messaging system through the 'mercury project,' focusing on enhancing reliability, modularity, and the adoption of functional programming. It outlines the challenges faced and the strategies implemented to create a more efficient and reliable messaging experience.

What You'll Learn

1

How to implement a modular JavaScript system to avoid regressions

2

Why test-oriented development is crucial for maintaining code quality

3

How to apply functional programming principles to improve code decoupling

Prerequisites & Requirements

  • Understanding of JavaScript and its module systems
  • Familiarity with unit testing concepts

Key Questions Answered

What challenges did the mercury project address in Facebook's messaging system?
The mercury project addressed issues such as disconnection, incorrect message counts, and missed or duplicated messages. It aimed to improve the reliability of the messaging system while ensuring quick and incremental loading, which is essential for a browser-based application.
How did modularity improve the development process in the mercury project?
Modularity was implemented to prevent regressions that often occurred due to mismanaged JavaScript dependencies. By adopting a system similar to CommonJS, where files are treated as modules, the team ensured that dependent modules are defined before evaluation, significantly enhancing code reliability.
What is the significance of test-oriented development in the mercury project?
Test-oriented development was emphasized to clarify module boundaries and enhance code quality. With over 85% test coverage, the mercury team could refactor code with minimal regressions, ensuring that all patches included unit tests, which reflects a culture of thorough code review.
How did the mercury project incorporate functional programming principles?
The mercury project embraced functional programming by replacing Object Oriented Programming (OOP) patterns with functional ones. This approach allowed for a highly decoupled system that supports fast, incremental loading, making it easier to manage real-time data updates without special treatment for initial data.

Key Statistics & Figures

Test coverage of mercury codebase
over 85%
This high test coverage has allowed the team to introduce new features and make architectural changes with minimal regressions.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Key Actionable Insights

1
Adopt a modular approach to JavaScript development to minimize regressions.
By treating each file as a module and ensuring dependencies are clearly defined, developers can avoid common pitfalls associated with global scope issues and improve code reliability.
2
Implement a robust unit testing framework to enhance code quality.
With a strong emphasis on unit testing, teams can refactor code confidently, knowing that tests will catch regressions before they reach production.
3
Transition to functional programming to create a more flexible and decoupled codebase.
Functional programming allows for simpler data handling and can lead to better performance in real-time applications, as it reduces the complexity associated with OOP.

Common Pitfalls

1
Developers often introduced regressions when making improvements due to a simplistic dependency management system.
This occurred because the system did not guarantee the order of file loading, leading to code that worked in development but failed in production. Adopting a modular approach can help mitigate this issue.

Related Concepts

Modular Javascript
Unit Testing
Functional Programming
Real-time Systems