Chapter 7: Bringing It All Together
The full system
With all six chapters complete, the system looks like this:
-
Neo4j Aura. Holds the supply chain graph – 20 suppliers, 12 warehouses, 10 distribution centers and 30 retailers connected by shipping relationships, loaded once in Chapter 2 and updated in real time as shipments arrive. It answers graph questions: what’s the cheapest path from a supplier to a retailer and which warehouse should we use when one goes offline.
-
Snowflake Postgres. Holds the live operational data – every shipment event consumed from Kafka, written in real time by the simulator. It answers OLTP questions: how many shipments are currently delayed, which shipments have been rerouted, when did W003 go offline and when did it come back.
-
Snowflake. Holds the analytical history – shipment data synced from Snowflake Postgres into
shipment_historyand aggregated for trend analysis. It answers analytical questions: which suppliers have the highest delay rates, which warehouses are breaching SLA thresholds, how has delay volume changed over the last hour.
None of these systems knows about the others. Aura knows nothing about Snowflake Postgres shipment records. Snowflake Postgres and Snowflake know nothing about the graph topology. The intelligence sits in the application layer. The simulator is the only component that talks to the graph: it asks Aura for a route and records the outcome in Snowflake Postgres. The analytics app moves data from Snowflake Postgres into Snowflake, and each dashboard reads from a single system.
Running the system
Once the three systems are set up, running the demo is one short sequence.
First time only – run each notebook once, in order:
02_neo4j_supply_chain.ipynb– Builds the supply chain graph in Aura.03_snowflake_postgres.ipynb– Creates the operational tables in Snowflake Postgres.04_snowflake_warehouse.ipynb– Creates the Snowflake database, schema, warehouse andshipment_historytable.
Every run:
- Stop the Streamlit apps if they’re running.
- Start the simulator,
05_simulator.ipynb. It resets the live state in all three systems before it begins, so you never clear anything by hand. - In a terminal:
streamlit run app.py. - In a second terminal:
streamlit run analytics_app.py --server.port 8502. - Let the simulator run for as long as you like, up to the one-hour limit. The notebook is set to stop after 1,000 events (
N_EVENTS = 1000). Change it to-1for a longer run. - Stop the simulator with the stop button. It restores any warehouse that is still offline.
Give the simulator a few minutes before looking at the analytics dashboard. The charts fill in as data accumulate, and a run of 15 to 20 minutes covers several disruptions.
06_analytics.ipynb is optional. It gives a static snapshot of the same data and uses its own scratch table, so you can run it at any time, ideally with the simulator stopped.
The one rule to remember is to stop the apps before restarting the simulator, because the startup reset empties the tables they read from.
What each system does that the others can’t
It’s worth noting why three systems are better than one for this use case.
Why not just Aura? Neo4j Aura is purpose-built for graph traversals – exactly what the disruption routing requires. Finding an alternative path that avoids an inactive warehouse mid-route is a natural graph query. In Cypher it’s a variable-length path with a WHERE NONE() filter. In SQL it would require a recursive CTE with exclusion logic that grows in complexity with each additional hop. The graph structure also makes it easy to answer questions about connectivity – such as which suppliers can reach which retailers – that would require expensive self-joins in a relational database.
Why not just Snowflake Postgres? Snowflake Postgres is purpose-built for operational data – high-frequency writes from the Kafka consumer, transactional consistency and low-latency reads for the live operations dashboard. It handles thousands of shipment inserts per session exactly as a production Postgres instance would. Standard psycopg2 connectivity, ON CONFLICT DO UPDATE for idempotent upserts and TIMESTAMPTZ for accurate event timing all work exactly as expected.
Why not just Snowflake? Snowflake is excellent for large-scale analytics and historical queries. Aggregating delay trends by minute, computing warehouse health scores across thousands of shipments and ranking suppliers by delay rate are all queries that benefit from Snowflake’s columnar storage and parallel execution. Running these queries against the operational Snowflake Postgres table could add load to the live system and slow down the simulator’s writes.
The three-system architecture isn’t complexity for its own sake. Each system does what it’s genuinely good at and the results are combined at the application layer.
Going further
The system as built is a working demo. Here are some directions for making it more realistic.
Real supply chain topology. The supply chain graph is generated synthetically with a fixed random seed. A natural extension is to load a real supplier-warehouse-retailer network from a CSV or an ERP system export. The MERGE-based loading pattern in Chapter 2 is already idempotent, so replacing the synthetic data with real data requires only changing the source.
Multiple disruptions simultaneously. The simulator disrupts one warehouse at a time. In reality, multiple warehouses can go offline at once – due to weather events, regional power outages or carrier failures. Extending the disruption lifecycle to track a set of disrupted warehouses rather than a single one would make the routing more challenging and the analytics more interesting.
Kafka Streams processing. The simulator currently consumes events one at a time in a tight loop. A natural production extension is to add a Kafka Streams application between the producer and the consumer that enriches events in real time – adding routing decisions, delay predictions or SLA breach flags before they land in Snowflake Postgres. This decouples the enrichment logic from the consumer and scales independently.
Real delay prediction. Delays are currently assigned at random: each shipment has a 15% chance of being delayed, with a uniform 15 to 239 minute duration, independent of suppliers, warehouses and disruptions. A more realistic model would use a machine learning model trained on historical delay data to predict delay duration based on supplier, warehouse, route and time of day, and could link delays to disruptions. The delay_minutes column is already in the schema – replacing the random draw with a model prediction requires only changing the event generation function.
Continuous replication. The incremental sync from Snowflake Postgres to shipment_history is handled in application code. Snowflake Postgres can also mirror tables into Snowflake continuously, which would remove the sync code from the analytics app and keep the warehouse copy current without any application involvement. Check the Snowflake documentation for the current availability of mirroring.
Streamlit Cloud deployment. Both Streamlit apps run locally in this demo. Deploying them to Streamlit Cloud would make the dashboards accessible from any browser without running a local server. You’ll need to commit the requirements.txt, add the credentials to Streamlit’s secrets management and make sure the hosted app can reach your Snowflake Postgres instance over the network.