In-Browser Execution for Bento's Lightweight Notebooks

Meta's internal Jupyter platform, Bento, supports workloads ranging from quick prototyping to heavy machine learning. Users running lighter tasks still had to reserve remote compute before executing any code, adding friction disproportionate to their needs. Bento now supports serverless execution directly in the browser via a WebAssembly-based infrastructure built on Pyodide.

Lite workloads are defined as those that consume data from upstream systems, produce no side effects to underlying systems, and stay within the maximum Chrome tab memory limit. Internal feedback indicated that for these workloads, the setup time and complexity outweighed the benefits. Requirements called for an intuitive, quick startup that skips remote compute reservation while supporting the majority of lite use cases.

Architecture of the Serverless Kernel

Kernel Bridge and Web Worker

Pyodide, a Python distribution for the browser running on WebAssembly, forms the foundation. A kernel abstraction around Pyodide performs message passing via the Jupyter Protocol, allowing Bento to interact with it as it would any classic kernel, with some limitations.

Serverless Jupyter notebooks

The kernel bridge is an abstraction layer that lets Bento work with both traditional server-based kernels and the new browser-based kernel without changes elsewhere in the system. Users see a selector in the notebook toggling between server-based and serverless kernels.

Serverless Jupyter notebooks

JavaScript's single-threaded nature necessitates running kernel operations in a web worker. Without one, expensive kernel operations would block the entire browser. The worker handles kernel operations and passes only results to the main thread.

Handling Magics

Cell magics are central to Bento's extension platform. Middleware captures these magics, processes them in the JavaScript context, and injects the expected results back into the Python kernel. This allows existing custom cells to work unchanged. The %%sql magic powering the custom SQL cell is one example of this pattern.

Meta-Specific Integrations

Integrations with existing extensions support the extract, transform, and load (ETL) narrative for a popular set of data operations.

Data Reads: SQL, Google Sheets, and GraphQL

The %%sql magic fetches warehouse data into the Pyodide kernel for further processing.

Serverless Jupyter notebooks - image5

The %%googlesheet magic retrieves data from a Google sheet into the notebook.

Serverless Jupyter notebooks

Meta's %%graphql magic powers the GraphQL cell, fetching data and injecting results into the kernel.

Serverless Jupyter notebooks

Dataframe Uploads

Uploads are handled differently from reads. The %%dataframe magic fetches arguments structurally, then an asynchronous job is kicked off using Tupperware, Meta's async tier compute platform. The cell output displays the status of that job.

Roadmap and Limitations

Plans include refining the lite workload heuristic, then defaulting new workloads to serverless. Workloads would be autodetected as lite based on memory, data volume, or library usage, and automatically switched to server-based kernels when too heavy, with minimal user interruption.

Additional Bento cell extensions are slated for integration to broaden what serverless execution supports. A key limitation is that homegrown libraries not ported to WebAssembly remain unavailable. Meta is exploring offloading execution of non-lite cells to remote infrastructure while keeping integration seamless with Pyodide. Once addressed, serverless notebooks are expected to become Bento's default landing experience.