When terrorists strike Iran, they usually target the Sistan-Baluchistan province on the country's border with Pakistan.
It was there in April that Jaish al-Adl, a Sunni Muslim insurgent group, killed 10 Iranian border guards. Between 2013 to 2015, the group killed at least 22 other border guards in a bid to call attention to religious discrimination against Iran's Sunni population.
Terrorist attacks in major Iranian cities are rare, which is one reason the near-simultaneous assaults Wednesday in Tehran were so remarkable.
They struck at the heart of the capital — the parliament building and the shrine of the founder of the Islamic Republic — leaving 17 people dead and dozens more injured.
Iran's Intelligence Ministry said five of the assailants were Iranians who had left the country to join the militant group, then returned last year, according to the state news agency.
So how has the Iranian government generally managed to avoid violence on such a scale?
For starters, demographics. The majority of Iranians are Shiite Muslims.
That makes them prime targets for Islamic State militants, who are Sunnis and consider Shiites to be apostates. But it also makes it difficult for the extremist group to successfully recruit Iranians to carry out attacks in their homeland.
About 9% of Iranians are Sunni, but most live in impoverished hinterlands. It is difficult for them to carry out attacks in more populated areas because of the travel, expense and logistics involved.
Iran also has a strong grip on domestic security. The police force, state Basij militia and border guards are deployed throughout the country, including the sensitive border region where many Sunnis live. The Islamic Revolutionary Guard Corps also has its own counter-terrorism unit responsible for gathering intelligence and carrying out covert operations within the country and abroad.
After Islamic State rose to prominence in 2014, Iran had to come up with a new counter-terrorism strategy, according to Ariane Tabatabai, an assistant professor of security studies at Georgetown University
Iran "noticed the Islamic State was more brutal and had a clear anti-Shiite and anti-Iran agenda," she said.
Part of Iran's strategy included a military offensive in Iraq and Syria to prevent fighting from spilling over into Iran. Iran sends military advisors to Iraq to help fight Islamic State and money and equipment to Syria to prop up President Bashar Assad.
In March 2016, the Iranian parliament voted to increase its counter-terrorism and cybersecurity budget with the aim of increasing surveillance to identify potential Islamic State operatives. Not long after, Iranian officials said they had prevented 1,500 Iranians from joining Islamic State and uncovered and stopped a terrorist operation that was planning attacks on 50 different targets in Tehran.
Iran also runs a propaganda campaign aimed at deterring Sunnis from radicalization.
It puts out messages both domestically and across its borders to counter Islamic State's use of Twitter, Facebook and other social media sites to recruit fighters. While the militant group plays up sectarian divides to appeal to Sunni minorities who face discrimination, Iranian propaganda downplays religious differences.
"Iran is reaching out to people beyond its border to say that the Islamic State is not actually Islamic and that there is no difference between Sunnis and Shiites," Tabatabai said. "Iran has had a tough time selling that message to people, but it's trying."
In March, Islamic State released a 36-minute video message in Persian urging Iran's Sunni population to attack the country's Shiite-led government.
It's unclear whether that inspired any of the assailants in the attack this week. But it is clear that Iran is a desirable target for the extremists.
"This attack shows us how Iran is no longer immune," said Vali Nasr, dean of Johns Hopkins' School of Advanced International Studies. "Attacks that we have seen in other Middle East cities and Western capitals [are] now happening in Tehran. Citizens cannot trust it won't happen again."
Follow me on Twitter @melissaetehad