PyCon DE & PyData 2026

Simulating the World using SimPy: A practical Example
, Titanium [2nd Floor]

Modern systems are complex - and testing them in real environments is often expensive, risky, or simply not reproducible. Simulation is a practical way to explore behavior under controlled conditions: run scenarios, validate assumptions, inject failures on purpose, and repeat experiments without touching production.

In this talk, I build a concrete event-based simulation with SimPy to compare load-balancing algorithms under different conditions. I’ll show how SimPy’s processes and events fit together, how to structure the simulation cleanly, and how to move beyond a one-off demo by making runs reproducible and configurable - using configuration files and a simple command-line interface.


Real-world systems are often too complex to test reliably, in the same environment and under the same conditions. Changes are hard to measure, edge cases are difficult to reproduce, and external influences can hide the real behavior of a system. Simulation offers a way to abstract from reality while staying close enough to produce meaningful results. It allows full control over system components, timing, and disruptions, and makes it possible to test many scenarios in a repeatable way.

The practical example of this talk focuses on simulating load-balancing algorithms. Load-balancers are a good example of systems that are hard to evaluate in real environments. Some tested algorithms have no existing implementation, others differ across platforms, and cloud environments introduce many uncontrollable factors such as network latency, cloud noise, and reoccurring background workloads. These factors make fair and consistent testing almost impossible.

The problem is addressed by building an event-based simulation using SimPy. The session explains how SimPy works by using Generators to create the events, and how time and processes interact inside a simulation. An architecture for a practical example for a load-balancer simulation is presented, showing how different components interact and how algorithms can be swapped and compared.

The talk also covers improvements made to the simulation, including a command-line interface for easier execution and a YAML configuration file for flexible setup. It concludes with practical tips and lessons learned when working with SimPy, helping to avoid common pitfalls and improve simulation design.

Overall, the session provides an introduction to simulation as a testing tool, a hands-on example using SimPy, and a realistic architecture for building and evolving simulations in Python.


Expected audience expertise in your talk's domain:: None Expected audience expertise in Python:: None Public link to supporting material, e.g. videos, Github::

https://github.com/Knalltuete5000/simgen

See also: Presentation (3.1 MB)

Cloud-Engineer at inovex helping to develop and provide a private cloud infrastructure with a focus on performance and optimization.