Skip to content

Analyze bus delays in Thun using a serverless approach

The Thun one-way traffic has improved the traffic situation for morning traffic from the right shore of Lake Thun. In the evening rush hour, however, travel times have become more unpredictable. Let's have a look at the delays based on data of the open data platform mobility Switzerland.


05.11.2024

Departure Schedule
Departure Schedule

Public transportation systems, especially buses, play a vital role in urban mobility. Yet, as cities grow and traffic conditions change, buses often face delays that can ripple across transit schedules, affecting thousands of commuters. Thun, has seen both improvements and challenges in its traffic infrastructure, particularly with recent changes like the Thun north bypass and adjustments to the city’s one-way system. These developments have brought a mix of benefits and challenges, especially for bus routes during peak travel times.

This article explores the current traffic situation in Thun and a serverless approach to analyzing bus delays using AWS services such as Lambda, S3, and EventBridge. By building an automated system with these AWS tools, we can create a scalable, cost-effective solution to continuously monitor, analyze, and respond to bus delay patterns.

The Traffic Situation in Thun

Over the past few years, Thun has implemented several changes to improve traffic flow, particularly in response to congestion and increased commuter traffic.

  • Thun North Bypass: The north bypass has helped reduce morning traffic for commuters coming from the right shore of Lake Thun into the city.
  • One-Way Traffic System in the City Center: To improve flow within the downtown area, Thun has introduced a one-way traffic system in key parts of the city. This change has helped ease traffic in some areas but can cause bottlenecks during afternoon and evening rush hours, as well as periods of high traffic due to events or tourist seasons.
  • Challenges During Evening Rush Hour: Despite improvements in the morning, afternoon and evening traffic congestion remains a challenge, particularly for buses returning to the city center. Increased vehicle traffic and bottlenecks from new traffic flows have made bus schedules less predictable, which can disrupt overall transit efficiency.

Given these factors, insights into bus delay patterns could help to identify problem areas, optimize routes, and reduce the impact of traffic congestion on public transit reliability.

Implementing an Automated Bus Delay Analysis with AWS Serverless Services

To monitor and analyze bus delays, AWS serverless services provide a robust and scalable solution. By combining AWS Lambda, Amazon S3, and Amazon EventBridge, we can set up an automated data pipeline that processes and analyzes delay data continuously. Here’s how this solution is implemented:

Solution Architecture
Solution Architecture

Data Ingestion

  • Time-Triggered Processing: Once a day an event triggers an AWS Lambda function (1) to load bus delay data from Switzerland’s Mobility Open Data Platform (2). This data include timestamps, delay durations and route numbers. The function filters out irrelevant information, format data for analysis and validate the structure and accuracy of the incoming data.
  • Storing Data in Amazon S3: Amazon S3 is used to store delay data (3). S3’s scalable storage capabilities make it a natural choice for managing large datasets without worrying about storage limits.

Data Processing

AWS Lambda allows us to create event-driven functions that process data. Here’s how Lambda is used within the pipeline:

  • Event-Triggered Processing: Each time new data is uploaded to the S3 bucket, an event trigger the AWS Lambda functions to process this data (4/5).
  • Calculating Metrics and Storing Insights: AWS Lambda functions perform calculations on the data (6), such as average delay per route and delay frequency during certain hours. Processed insights are stored back in an S3 bucket ( 7).

Benefits of Using AWS Serverless Services for Bus Delay Analysis

An AWS serverless approach offers a number of benefits that make it particularly suitable for analyzing and responding to bus delays in real time.

  • Scalability: AWS serverless services like Lambda and S3 automatically scale according to the workload, making it easy to handle large volumes of data. This scalability is ideal for processing varying data volumes without additional infrastructure costs.
  • Cost-Efficiency: Serverless services operate on a pay-per-use model, meaning we only pay for the resources we use. This is particularly cost-effective for bus delay analysis, which may only require processing data at certain intervals or times of day.
  • Automated Data Pipeline: With Lambda and EventBridge, the entire data processing pipeline can run automatically with minimal human intervention.

Results

Timeframe: 01.07-2024 - 31.08.2024.

Daily Charts

Routes with the longest delays at 'Bahnhof Thun' station.

Route 21 - August
Route 21 - August
Route 25 - August
Route 25 - August

Monthly Charts

Days with the longest delays at 'Bahnhof Thun' station.

07.08.2024
07.08.2024
15.08.2024
15.08.2024

Conclusion: Using Data-Driven Insights to Improve Transit in Thun

Thun’s traffic situation presents both opportunities and challenges, particularly for its public bus system, which is affected by evolving traffic patterns. By leveraging AWS serverless services, we can implement a powerful and scalable solution to monitor, analyze, and respond to bus delay patterns. AWS Lambda, S3, and EventBridge work together to create a fully automated pipeline.

With this AWS serverless setup, we can gain valuable insights into delay patterns and better anticipate peak congestion times.

Resources