  It is increasingly common to outsource network functions (NFs) to the cloud.
However, no cloud providers offer NFs-as-a-Service (NFaaS) that allows users to
run custom NFs. Our work addresses how a cloud provider can offer NFaaS. We use
the emerging serverless computing paradigm as it has the right building blocks
- usage-based billing, convenient event-driven programming model and automatic
compute elasticity. Towards this end, we identify two core limitations of
existing serverless platforms to support demanding stateful NFs - coupling of
the billing and work assignment granularities, and state sharing via an
external store. We develop a novel NFaaS framework, SNF, that overcomes these
issues using two ideas. SNF allocates work at the granularity of flowlets
observed in network traffic, whereas billing and programming occur on the basis
of packets. SNF embellishes serverless platforms with ephemeral state that
lasts for the duration of the flowlet and supports high performance state
operations between compute units in a peer-to-peer manner. We present
algorithms for work allocation and state maintenance, and demonstrate that our
SNF prototype dynamically adapts compute resources for various stateful NFs
based on traffic demand at very fine time scales, with minimal overheads.
