(CNN) -- Tuesday marked the last day of the Hajj, the annual pilgrimage that sees over two million Muslim pilgrims journey to Mecca in Saudi Arabia.
It is one of the most celebrated events in the Islamic calendar, and one of the world's largest public gatherings. Handling a crowd of that magnitude hasn't always been easy, especially in light of public health worries and ISIS fears.
To ensure such a feat goes off with minimal disruption, Saudi Arabia's authorities have had to go high-tech.
Any event that draws crowds a million strong faces the risk of stampedes. Hajj pilgrims have not always been exempt from such a fate. The worst incident occurred in 1990, when 1,426 pilgrims were trampled to death. A similar event took place in 2006, when 363 people lost their lives. Since then, the Saudi government has used live crowd analytics software CrowdVision to manage the throng.
"It spots patterns of crowd behavior that indicate potential danger such as high densities, pressure, turbulence, stop-and-go waves and other anomalies," Fiona Sterns, CrowdVision's co-founder, told the BBC.
Back in a central control room, police and military personnel monitor the live data feeds provided by the software, which lets them see in real-time where the crowds are thickest.
Transporting two million people at once has the potential of setting new records in gridlock. To combat this, authorities employ 15,000 public buses to help move the masses between the holy sites. Like the crowds, the buses' movements are also tracked by wireless monitors to help authorities grasp where traffic jams hold up the procession, and make adjustments accordingly.
The government has also invested in several long-term public transport initiatives to take some pressure off the roads.
The Al Mashaaer Al Mugaddassah Metro was completed in 2011, and ferries pilgrims between Mecca, Mount Arafat, Muzdalifah and Mina -- all required stops on the Hajj. The railway line was designed to shuttle 72,000 passengers an hour. Construction has also begun on a four-line metro system for the city of Mecca.
While various health crises -- namely MERS and Ebola -- have cast a shadow over this year's proceedings, organizers employed a medical army to address any health issues that might arise.
According to the World Health Organization (WHO), this year there were 180 ambulances on standby, as well as 22,000 health care professionals, 141 health centers, 25 hospitals with 5,250 beds, and 19,000 units of varying blood types. Officials also banned pilgrims from Ebola hot zones -- namely Guinea, Liberia and Sierra Leone.
"WHO has been closely coordinating with the Ministry of Health of Saudi Arabia to ensure that preparedness measures are in place," says Rana Sidani, a WHO spokesperson.
The rise of ISIS and other Islamic extremist groups in the region put added pressure on Saudi Arabia this year to increase security measures during the Hajj.
"I would not put it past ISIS to try to disrupt the Hajj and I think Saudi authorities are well aware of that possibility," said Fahad Nazer, a terrorism analyst at JTG Inc and a former political analyst at the Saudi embassy in Washington, told The National.
To safeguard against the possibility of attack, officials installed thousands of CCTV cameras throughout the country, focusing on the holy sites, and employed facial recognition technology. They also employed 60,000 security troops.
"These forces will be stationed in Mina, Arafat and Muzdalifah to ensure the safety of pilgrims and enable them to perform their rites with ease and comfort," Major General Osman Al Mahraj, director of general security, told the Saudi Gazette.