Serverless Jupyter Notebooks at Meta

At Meta, Bento, our inner Jupyter notebooks platform, is a well-liked software that enables our engineers to combine code, textual content, and multimedia in a single doc. Use circumstances run your entire spectrum from what we name “lite” workloads that contain easy prototyping to heavier and extra advanced machine studying workflows. Nevertheless, despite the fact that the lite workflows require restricted compute, customers nonetheless need to undergo the identical strategy of reserving and provisioning distant compute – a course of that takes time – earlier than the pocket book is prepared for any code execution.

To deal with this downside, we now have invested in constructing infrastructure that enables for code execution straight within the browser, eradicating the necessity to provision distant compute for some lite workloads. This infrastructure leverages a library referred to as Pyodide that sits on high of WebAssembly (Wasm)

Right here’s how we married Bento with this in-browser, serverless code execution know-how to energy our notebooks platform for these lite workloads.

The motivation for supporting lite workloads

We outline lite workloads as workloads that solely devour knowledge from upstream methods, do not need unwanted side effects to our underlying methods, and use as much as the utmost Chrome tab reminiscence restrict. We regularly get inner suggestions from the house owners of those lite workloads that the time and complexity in getting began will not be proportionate to what they wish to use Bento for. 

The necessities might be summarized as follows:

  • An intuitive startup course of that works proper out of the field 
  • A startup course of that could be very fast and has the pocket book instantly prepared for execution 
  • A startup course of that doesn’t embody the advanced distant compute reservation course of 
  • An execution setting that helps the vast majority of the lite workloads

How we put the items collectively

Serverless Jupyter notebooks

How this all works

Pyodide (a Python distribution for the browser that runs on WebAssembly) is a crucial ingredient for this work. We’ve constructed a kernel abstraction round this which, when referred to as from Bento, will simply work as any of the traditional kernels we now have (with some limitations) and carry out message passing utilizing the Jupyter Protocol.

Kernel bridge 

That is simply an abstraction that enables Bento to work with each conventional server-based kernels and this new browser-based kernel with no modifications in any respect to the remainder of the system. The seen manifestation of that is only a selector within the pocket book that toggles between server-based kernels and serverless.

Serverless Jupyter notebooks


Cell magics are an essential  part of the Bento extension platform. As a way to permit current customized cells to work with no modifications, we constructed middleware to seize these cell magics, course of them straight within the context of javascript, after which simply inject the anticipated outcomes again into the Python kernel. An excellent instance of this sample is round %%sql, which we use to energy our customized SQL cell. 

We’ll showcase a number of extra examples within the part beneath on “Meta-specific” integrations.

Why we’d like a webworker

Since JavaScript is single-threaded, within the absence of a webworker, your entire browser would simply lock up when we now have “costly” kernel operations. Having kernel operations run in a webworker with simply the outcomes being handed to the principle thread helps mitigate this.

Meta-specific integrations 

As a way to unlock extra utility and have a coherent story across the extract, rework, and cargo (ETL) narrative, we constructed integrations with an preliminary set of current extensions. These characterize a comparatively common set of extensions that customers leverage to carry out knowledge operations.

SQL Cell

This leverages the %%sql magic to fetch knowledge from the warehouse and make it out there for additional processing within the Pyodide kernel.

Serverless Jupyter notebooks - image5

Google Sheets 

Right here, we leverage the %%googlesheet magic to fetch knowledge from a Google sheet and make it out there for additional processing within the pocket book.

Serverless Jupyter notebooks


Right here, we leverage %%graphql magic, which powers the GraphQL cell to make knowledge fetches after which inject the consequence again into the kernel for additional processing.

Serverless Jupyter notebooks

Dataframe uploads

Knowledge uploads are a bit trickier to tug off as in comparison with the information reads we showcased above. We as an alternative obtain this performance by:

  1. Leveraging the %%dataframe magic that powers the add customized cell with a purpose to fetch the arguments in a structured means.
  2. We then kick off an async job utilizing Tupperware (Meta’s async tier compute platform) and present the standing of the related tupperware job within the cell output.

What’s subsequent for serverless notebooks

Whereas we’ve addressed the preliminary set of challenges to deliver this product on-line, there may be nonetheless a whole lot of work to be accomplished to enhance the developer expertise for customers. Firstly, we’re planning on bettering the lite workloads heuristic. As soon as we now have this found out, the subsequent step will contain defaulting all new workloads to start out as serverless. Then we are able to shortly autodetect (based mostly on reminiscence necessities, knowledge volumes, or libraries in use) whether or not the workload is lite sufficient. If not, we are able to mechanically swap that pocket book to leverage a server-based kernel with minimal interruption to the person stream.

After this, we plan to combine with extra current cell extensions constructed on high of the Bento platform and thus broaden the scope of what’s doable when operating “serverless.”

The largest limitation with this strategy at Meta is that homegrown libraries that haven’t been ported to WebAssembly will likely be unavailable. Given this, we’re additionally planning to discover whether or not we are able to farm out the execution of particular “non-lite” cells to our distant execution infrastructure whereas making this work seamlessly with Pyodide.

As soon as these have been addressed, “serverless” notebooks will develop into the de facto touchdown expertise in Bento.


Among the approaches we took had been straight impressed by the work accomplished on JupyterLite and straight leverages the Pyodide library with out which this mission wouldn’t have been doable. I’d additionally wish to thank all of the engineers at Meta I collaborated with to make this mission a actuality.