Slide 1

Slide 1 text

FLAME: Better Serverless architecture with Kubernetes Google DevFest 2024 • Ali Auditorium, Lahore

Slide 2

Slide 2 text

Systems architect & technology advisor for startups and enterprises. Find me anywhere @sheharyarn Sheharyar Naseer

Slide 3

Slide 3 text

Background ‣ Indie Nomad Software Architect ‣ 14+ years of polyglot experience, focus on Web & Cloud ‣ Worked with Apple, TheScore, Superlist, A1, Slab, etc. ‣ StackOverflow: 75,000+ score (Top 5 in Pakistan) ‣ Author / Contributor of multiple famous libraries & tools ‣ Featured on popular developer communities

Slide 4

Slide 4 text

State of Serverless Infra with Kubernetes The FLAME Pattern FLAME with Kubernetes Tooling and Ecosystem Q/A and Learning Resources Outline

Slide 5

Slide 5 text

Serverless ‣ Just write and deploy code ‣ Don't manage infrastructure ‣ Elastic scale ‣ Runs on demand ‣ Pay what you use, avoid idle usage ‣ GCP Functions, AWS Lambda, Cloudflare Workers, etc.

Slide 6

Slide 6 text

Serverless, but... ‣ End up having more complexity ‣ Add more microservices ‣ Glue code: Messaging queues, storage, more APIs ‣ Dev, Testing and CI complexity ‣ Proprietary Javascript ‣ Managing everything but scale

Slide 7

Slide 7 text

Kubernetes ‣ Manage and deploy your own servers ‣ K8s: Container automation framework ‣ Control scale, provisioning, resources, etc. ‣ Comprehensive API ‣ Not exclusive from Serverless

Slide 8

Slide 8 text

Kubernetes & Serverless ‣ K8s is not exclusive from Serverless ‣ K8s serverless frameworks: ‣ OpenFaas, Kubeless, KNative ‣ Many more... ‣ Underlying problem remains the same

Slide 9

Slide 9 text

Imagine if we could auto-scale parts of an app by simply running them in a temporary copy of the app. - C H R I S M C C O R D

Slide 10

Slide 10 text

FLAME Pattern

Slide 11

Slide 11 text

FLAME ‣ "Fleeting Lambda Application for Modular Execution" ‣ Entire application is a Lambda ‣ Parts executed on short-lived infra ‣ No rewrites or glue, uses existing app code ‣ Handles infra management ‣ Removes the problem, instead of solving it

Slide 12

Slide 12 text

FLAME Work fl ow ‣ Writing your app to run all locally ‣ Containerize/Deploy ‣ Find parts that need to be scaled independently ‣ Don't split them out to a separate service ‣ Wrap it in a FLAME runner function ‣ That's it!

Slide 13

Slide 13 text

Example ‣ Developing YouTube ‣ Users can upload videos ‣ Select thumbnails for videos ‣ Feature: Thumbnail generation for videos ‣ FFMPEG → Expensive, CPU-intensive ‣ Show available thumbnails as generated

Slide 14

Slide 14 text

Example, Usage... def generate_thumbnails(video, interval) do tmp = Path.join(System.tmp_dir!(), Ecto.UUID.generate()) File.mkdir!(tmp) System.cmd("ffmpeg", [ "-i", video.url, "-vf", "fps=1/ # { interval}", " # { tmp}/%02d.png" ]) urls = Storage.put_thumbnails(video, Path.wildcard(tmp < > "/*.png")) Repo.insert_all(Thumb, Enum.map(urls, &%{video_id: video.id, url: &1})) end

Slide 15

Slide 15 text

Example, Usage... def generate_thumbnails(video, interval) do FLAME.call(MyApp.VideoRunner, fn - > tmp = Path.join(System.tmp_dir!(), Ecto.UUID.generate()) File.mkdir!(tmp) System.cmd("ffmpeg", [ "-i", video.url, "-vf", "fps=1/ # { interval}", " # { tmp}/%02d.png" ]) urls = Storage.put_thumbnails(video, Path.wildcard(tmp < > "/*.png")) Repo.insert_all(Thumb, Enum.map(urls, &%{video_id: video.id, url: &1})) end) end

Slide 16

Slide 16 text

Example, Con fi g... def start(_type, _args) do flame_parent = FLAME.Parent.get() children = [ . . . , MyApp.Repo, {FLAME.Pool, name: MyApp.VideoRunner, min: 0, max: 10, max_concurrency: 5, idle_shutdown_after: 30_000}, !flame_parent & & MyAppWeb.Endpoint ] # . . . end

Slide 17

Slide 17 text

FLAME with K8S ‣ FLAME can manage infra using Kubernetes API 1. Provisions new runner 2. Runner connects to parent 3. Parent sends runner function for execution 4. Runner returns result back to remote parent caller 5. Runner idles down FLAME.call(MyApp.Runner, fn - > # Your regular app code end)

Slide 18

Slide 18 text

Tooling & Ecosystem Libraries: ‣ bit.ly/flame-elixir ‣ bit.ly/flame-js-wrapper Infrastructure support: ‣ Kubernetes ‣ Fly.io

Slide 19

Slide 19 text

Questions? These Slides More Talks Video Demo Blog Post Docs shyr.io/t/flame-k8s shyr.io/talks bit.ly/flame-demo fly.io/blog/rethinking-serverless-with-flame bit.ly/flame-elixir → → → → →  @  shyr.io [email protected] @sheharyarn