@vipulgupta2048

Mistakes, pain and learnings of scaling Python applications on millions of IoT devices

I am Vipul!

@vipulgupta2048

We-pull

  • Product Owner & Documentation Lead at balena
  • Run a docs initiative called Mixster
  • Volunteers @ PyCon India & ALiAS
  • Pronouns: He/him/his

@vipulgupta2048

This is a Raspberry Pi

@vipulgupta2048

It ain't much ...

@vipulgupta2048

Devices like this power...

CO2 sensors, farms, smart dustbins, cars, locks, your room, home devices...

@vipulgupta2048

and more like this...

Underwater drones, satellites, parking, and your talking wireless speakers

@vipulgupta2048

@vipulgupta2048

The challenges

With smart cities & even your toaster running applications.
The stakes have never been higher

While building software is hard.

@vipulgupta2048

Building it right for IoT is painful.

@vipulgupta2048

@vipulgupta2048

@vipulgupta2048

@vipulgupta2048

Considerations when selecting
an IoT device

  • Architecture?
  • CPU, RAM, GPU?
  • Wifi/ethernet/sim?
  • Peripherals needed?
  • TPM chips? 
  • GPIO headers? 

@vipulgupta2048

Considerations using
Python for IoT

  • Is it supported on ARM v8?
  • Is 4GB of RAM enough to run it?
  • Does the use-case need internet? 
  • Is there a gstreamer wrapper library?
  • Does it support microcontrollers?

@vipulgupta2048

@vipulgupta2048

@vipulgupta2048

Ideating your IoT product

  • What resources you need?
  • What limitations your usecase has?
  • What hardware is available out there?
  • Repeat.

Your will decide if your product or dies before launch. No pressure.

@vipulgupta2048

And
That's what we are talking about today

@vipulgupta2048

Tight feedback loops between environments

Dev == testing == staging == prod

@vipulgupta2048

Build an SBOM

Track, assess and obsess

@vipulgupta2048

@vipulgupta2048

@vipulgupta2048

@vipulgupta2048

"It works on my system"

Adding another dimension of hell

@vipulgupta2048

Memory Management and Resource Constraints

@vipulgupta2048

Let me tell you a story ...

@vipulgupta2048

@vipulgupta2048

Storage Considerations for IoT Devices

  • SD cards in production. Toxic relationship.
  • Go easy on storing all your print() and logging.info()
  • Use services like Datadog to store your logs.

@vipulgupta2048

Reproducible Self-Healing Setup

  • Recovery of the device is better than crashlooping
  • Proper crash reporting pays dividends
  • If you have to reboot, then you are doing wrong

@vipulgupta2048

@vipulgupta2048

@vipulgupta2048

Make sure your code

  • Retries with exponential backoffs
  • Can take into account race conditions
    • Doesn't rely on timing but on eventual consistency
  • Perform setup or teardown processes
  • Has a "heartbeat" comms 

@vipulgupta2048

Building Fault-Tolerant Applications

  • Handle intermittent network issues gracefully.
  • Prevent excessive bandwidth consumption.
  • Don't be using your swap memory. 
  • Connect your peripherals on runtime, not bootime

@vipulgupta2048

@vipulgupta2048

Going beyond the code

  • HiTL pipelines for testing
  • Choosing a space-efficient embedded OS
  • Keep a way to remotely access a device
  • Communication infra optimized for IoT
    • Use MQTT instead of HTTPS
    • Use pub-sub model
    • Account for flaky connectivity 

@vipulgupta2048

But Vipul, how can I use this now at work?

@vipulgupta2048

@vipulgupta2048

@vipulgupta2048

And, that's about it!

Questions? Collaborate? Work with us? Reach out!

Vipul Gupta

Reviews cheesecakes, solves GitHub issues & "rights" docs

And, that's about it!

Questions? Collaborate? Work with us? Reach out!

Vipul Gupta

Reviews cheesecakes, solves GitHub issues & "rights" docs

Credits

  • https://acoptex.com/wp/overview-of-raspberry-pi-4-model-b/ 
  • https://pythondev.readthedocs.io/platforms.html
  • https://imgflip.com for the memes
  • https://www.researchgate.net/figure/Smart-Parking-System-Talking-of-the-above-mentioned-figure-it-depicts-a-parking-area_fig1_303842610
  • https://mixster.dev/2022/10/18/no-soldering-ambient-lighting/
  • https://blog.balena.io/assets/2023/02/os-testing-autokit-rig.png
  • https://blog.upbound.io/hashicorp-bsl-license-change
  • https://www.cisa.gov/sbom
  • https://github.com/balena-io-examples/balena-python-hello-world
  • https://raspberrypi.org

[PyDelhiConf '23] Deploying Python on the edge: Mistakes, pain and leanings of scaling Python applications on millions of IoT devices

By Vipul Gupta

[PyDelhiConf '23] Deploying Python on the edge: Mistakes, pain and leanings of scaling Python applications on millions of IoT devices

Unlock the power of Python on the edge! Optimize your deployments for resource-constrained uptime-critical environments. Join the session to level up your IoT applications using Python.

  • 170