Bus transportation system has become the primary mode of traffic for urban residents. Every day, thousands of buses provide services for millions of passengers. Efficiently monitoring bus trajectories is essential for evaluating service quality and ensuring public safety. In this study, we propose a Flink-based solution to detect anomalies for bus trajectories in real time. Specifically, it can identify two types of anomalies. The first type is when a bus deviates from its designated route during a trip. The second type is when a bus arrives at a scheduled stop along its route but fails to stop. This solution employs CEP (Complex Event Processing) to determine bus arrival events and control the detection process. In this process, it utilizes the state management mechanism to save and update a bus’s actual trajectory, which is derived from the raw GPS trajectory and maintained as a stop sequence. Subsequently, it uses LCSS (Longest Common Subsequence) to measure the trajectory similarity between the actual bus trajectory and the scheduled route. We validate the solution using a large-scale real dataset in a Flink cluster with six virtual machines. The experimental results show that (1) each core can handle anomaly detection on 12.5 buses simultaneously and (2) the detection accuracies of the two anomalies are 90.5% and 89.3%, respectively.