Meteor migration from Fibers to Async 2023–2024 ☄️
Published on Nikolay Aleshkovskiy, Timofei Leonov
Related articles:
Current state of Meteor JavaScript framework and platform
The Meteor JavaScript framework was introduced in 2012 and revolutionized the world of web development with its modern approaches, including real-time data, code sharing, and server-side code written in a synchronous manner.
In 2023, the Meteor team decided to transition from the original Node Fibers-based approach to a native async/await approach.
This means that all server-side code written in a synchronous style will need to be refactored refactored and rewritten in a modern async/await style. Some client-side code sections will be affected by this change as well.
Who we are?
Nikolay and Tima — small part of Milk & Cartoons development team, working mainly with Meteor.js framework.
We have a few colleagues who use Meteor from time to time, but we work on applications based on the on the Meteor platform on a daily basis.
We have gained tons of experience during the last 5 years of Meteor.js development . We've worked with complex methods and publications/subscriptions, MongoDB optimization, Atlas search indexes.
And of course we've been working intensively on moving our apps from Meteor v2 to v3 async API.
📌 Why should I update a Meteor based project from Fibers to async/await functions as soon as possible
Currently, the latest version of the Meteor framework runs on Node.js v14, which is an older version. The Node.js team has already dropped support for v14 as it is considered outdated. However, the Meteor team will maintain support for v14 until April 2024.
Using older versions of Meteor and Node.js after April 2024 will leave you vulnerable to security threats as it will no longer receive updates or patches.
What is Node.js Fibers?
Node.js is known for its single-threaded, event-driven architecture. This design allows Node.js to handle a large number of connections simultaneously without the overhead of creating and managing multiple threads. The event-driven model, coupled with non-blocking I/O operations, enables Node.js to be highly performant and scalable, making it well-suited for building real-time applications, web servers, and other networked software.
In the context of Node.js, asynchronous (async) code refers to a programming paradigm where operations can be initiated and continue to execute without waiting for their completion. Instead of blocking the execution of subsequent code, Node.js employs an event-driven, non-blocking model that allows asynchronous tasks, such as I/O operations or network requests, to occur concurrently.
The Node.js fibers package offers a solution for working with synchronous-style code in an asynchronous environment. It introduces fibers, which are lightweight, cooperative threads managed by the V8 JavaScript engine. Developers can use fibers to write asynchronous code in a synchronous manner, making it easier to reason about and maintain.
What is async and sync code flow?
Synchronous code executes in a sequential and blocking manner, where each operation is completed before moving on to the next. It follows a linear flow, making it easy to read and understand but may lead to performance issues if a task takes a significant amount of time.
On the other hand, asynchronous code allows multiple operations to be initiated without waiting for each to complete. It uses mechanisms like callbacks, Promises, or async/await syntax, enabling non-blocking execution, improved responsiveness, and efficient handling of concurrent tasks, especially in scenarios involving I/O operations or network interactions.
The key difference lies in the execution flow: synchronous code progresses step by step, while asynchronous code enables parallelism and responsiveness.