Share
Embed
FLAME - Better Serverless Architecture with Kubernetes
My talk about using the new FLAME programming pattern with Kubernetes. Given at DevFest Lahore 2024.
Sheharyar Naseer
December 15, 2024
Transcript
19 slides
-
FLAME: Better Serverless architecture with Kubernetes Google DevFest 2024 •
Ali Auditorium, Lahore -
Systems architect & technology advisor for startups and enterprises. Find
me anywhere @sheharyarn Sheharyar Naseer -
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 -
State of Serverless Infra with Kubernetes The FLAME Pattern FLAME
with Kubernetes Tooling and Ecosystem Q/A and Learning Resources Outline -
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. -
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 -
Kubernetes ‣ Manage and deploy your own servers ‣ K8s:
Container automation framework ‣ Control scale, provisioning, resources, etc. ‣ Comprehensive API ‣ Not exclusive from Serverless -
Kubernetes & Serverless ‣ K8s is not exclusive from Serverless
‣ K8s serverless frameworks: ‣ OpenFaas, Kubeless, KNative ‣ Many more... ‣ Underlying problem remains the same -
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 -
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 -
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! -
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 -
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 -
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 -
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 -
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) -
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