Upgrade to Pro — share decks privately, control downloads, hide ads and more …

FLAME - Better Serverless Architecture with Kub...

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
Tweet

More Decks by Sheharyar Naseer

Other Decks in Technology

Transcript

  1. 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
  2. State of Serverless Infra with Kubernetes The FLAME Pattern FLAME

    with Kubernetes Tooling and Ecosystem Q/A and Learning Resources Outline
  3. 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.
  4. 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
  5. Kubernetes ‣ Manage and deploy your own servers ‣ K8s:

    Container automation framework ‣ Control scale, provisioning, resources, etc. ‣ Comprehensive API ‣ Not exclusive from Serverless
  6. Kubernetes & Serverless ‣ K8s is not exclusive from Serverless

    ‣ K8s serverless frameworks: ‣ OpenFaas, Kubeless, KNative ‣ Many more... ‣ Underlying problem remains the same
  7. 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
  8. 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
  9. 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!
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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)
  15. 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