https://vcz.fr

Vincenzo Scalzi

Building FaaS apps… FaaSt!

About me

👋 Vincenzo Scalzi speaking!

I work as:

Cloud & DevOps Architect

@ Pyl.Tech

I love:

- Enjoying my time in meetups

- Talking about emerging tech

- Privacy and minimalism

🐘

FaaS?!

A simple definition

simplified

Yes, FaaS!

...for Function as a Service, also wrongly called "Serverless".

 

The latest paradigm shift in computing infrastructure. One that involves code… mostly.

 

We will mention AWS Lambda and Cloudflare Workers in later slides.

Rick and Morty S1E5 "Meeseeks and Destroy"

Top-down view of FaaS

  • Spawn function environment
  • Handle request
  • Execute request
  • Destroy function environment

The Stack

Here are some different options to host a service:

Hosting the infrastructure

Renting capacity

Allocating capacity

Deliver code

Rent the service!

OS

App

App

App

OS, Runtime

ƒ

Pay as you go, based on usage.

Handle the code, infra is managed.

Key takeaway

The shiƒt

Spot the difference

What would that change in my code?

Mind the size

Unlike classical development, functions are meant to be self-contained.

This translates to the necessity to specialize your functions, especially when your project scales in size.

deps

assets

ƒ code

deps

assets

ƒ code

deps

assets

ƒ code

Beware: more builds can become a maintainability nightmare!

Mind the deps

In addition, dependencies and external assets must be kept at a minimum.

You can send the assets to an external storage space. As for common dependencies, check if your provider supports them.

deps

ƒ

deps

ƒ

common

deps

assets

Mind the code!

Use every technique to reduce build size: tree shaking, compression, uglification, comment stripping, etc.

deps

ƒ

Tree shaking

Compress / Uglify

Integrate with your provider if it can further simplify your code: pre-included libraries, secrets management, key-value store, metrics, logging, feature toggles, etc.

Mind the provider

Depending on your service provider, the runtime may propose more recent language versions enabling the usage of a more recent target language.

Look for reference architectures or additional options such as ARM support or green workers.

ƒ

ƒ

common

deps

assets

provider

deps

Key takeaway

Land to cover with FaaS is wide.

Practices change, follow the guide.

How do I...?

Code!

Build!

Lint

Check the syntax

Test!

Deploy

Monitor

Maintain

Debug

Trace

Log

Plan for changes

Document

Review!

Plan the Architecture

Migrate to this solution

Use it with other services

A/B

Benchmark

Analyze costs

Upgrade

Release!

Assess performance

Foobar

Version  the

code

Coding fun

You can use the same IDE and will just need to target the latest version of the runtime recommended by your cloud provider.

The same goes for linting, versioning, building and testing. The only difference is that your code may not look the same.

> vi main.ts_

Building joy

Building is also identical! Retrieve your dependencies, compile your code, execute some tests and it will be ready to go.

However, since you will rarely change all the functions in a project, it is recommended to only rebuild the ones that changed. This could save valuable time and headaches.

> killall vi

> make build_

Deployment blast

Things are different when it comes to deployment. Each tool comes with a set of advantages and drawbacks.

You may choose between Serverless, SAM, Wrangler and many more or do it yourself with Terraform or any IT automation tool using your cloud provider's API.

You guessed right: this is not the simplest step.

> sleep 600_

After party

How to observe the very time-sensitive? To catch errors as soon as they happen?

These questions have no definitive answers. Default to provider solutions or common app practices when in doubt.

> exit_

Needs are plenty, answers are scarce.

Knowledge all over, growing yet sparse.

Key takeaway

DEMO

TIME!

What did we learn?

  • Cloudflare Workers deploys code worldwide
     
  • Code is executed where it's optimal (closer to user or service)
     
  • It is possible to work from their online editor
     
  • Node.JS and WebAssembly are supported

DEMO

TIME!

What did we learn?

  • AWS Lambda is comprehensive but comes with a learning curve
     
  • Many programming languages are natively supported
     
  • AWS Lambda is well connected to other AWS offerings
     
  • Complex configuration means manually creating Lambdas is hazardous

A word of caution

⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️ ⚠️

Remain critical of FaaS...

Before using FaaS, assess their relevance for your project. Equivalent solutions exist like managed container services.

Are chunks of the code supposed to function independently? What are my fallback solutions when I need to upgrade one component? What guarantees do I get from FaaS that I cannot get from more traditional approaches? Doesn't cost get out of control? Don't I need to write more code to get to the same result? Are developers ready for the switch? Is it necessary to get into devops to get started? Is it necessary to have cloud expertise to get started? What does it change in terms of cloud and software architecture? Wouldn't it be wise to wait for Serverless technologies to mature? How is it possible to guarantee security in such constrained environments? How to achieve the same quality of deployment with Serverless technologies? What is the performance vs. managed environment trade-off? What is it possible to gain from this change? Is this new computing model sustainable? Who is accountable in the case of a failure? Can we afford to R&D into Serverless technologies? Is our organization mature enough to make this switch? Is this solution really cost-effective? Are there unknown side effects to Serverless technologies? Is it too soon? Are my other applications compatible with this model or would I need to convert them as well? How well does it interact with external services? How well does it play with specialized software?

... because there are horror stories

... and bad incentives

per M rqs. per M GB•s
AWS Lambda x86 eu-west-1 $0.20 $16.67 (Wall time)
AWS Lambda ARM eu-west-1 $0.20 $13.34 (Wall time)
AWS Lambda@Edge eu-west-1 $0.60 $50.01 (Wall time)
Amazon CloudFront functions $0.10 *
Cloudflare Workers $0.15 $12.50 (CPU time)

Providers are incentivized to offer slower infrastructure to their FaaS offerings; requests taking more time to complete means more to bill to the customer.

... and cargo culting

Cargo cult programming can also refer to the practice of applying a design pattern or coding style blindly without understanding the reasons behind that design principle. Some examples are adding unnecessary comments to self-explanatory code, overzealous adherence to the conventions of a programming paradigm, or adding deletion code for objects that garbage collection automatically collects.

i.e. design an architecture that makes sense today, don't shoehorn everything into a standard.

... and many questions left unanswered

This presentation scratched the surface and intentionally took shortcuts.

Do you have any question?

That is all folks 🎉

https://vcz.fr

Vincenzo Scalzi