The embassy, at least in its traditional form, is facing an existential crisis. The global transformations of the twenty-first century have dramatically changed the way nations practice diplomacy. The rise of digital communications, diminishing resources, and growing security threats all raise the question of whether the traditional embassy is still relevant.

More than half of the developed nations in the Organization for Economic Cooperation and Development (OECD) have reduced their diplomatic footprint over the last decade, according to our research at the Lowy Institute, where we have constructed the Global Diplomacy Index, which charts almost 6,000 diplomatic posts across nearly 660 cities around the world. As government budgets shrink, embassies and diplomats seem more like expensive luxuries than political assets. It doesn’t help, of course, that diplomats are stereotyped as overpaid and ineffectual cocktail-circuit regulars and that foreign ministries frequently fail to reflect the times. They generally lack diversity and are slow to embrace innovation, even social media. Australia’s diplomats in Indonesia, for example, were still not using social media in 2010, even though Indonesia is the site of one of its most significant embassies, the largest recipient of Australian aid, and one of its most important neighbors in Asia. Despite being described as a “digital dinosaur” in 2010, the secretary of Australia’s Department of Foreign Affairs admitted in 2012 that he still did not consider digital diplomacy a high priority. And with the rising importance of economic diplomacy, governments are more inclined to open trade offices and innovation hubs than embassies. For example, our research indicates that between 2009 and 2015 the United Kingdom’s Foreign & Commonwealth Office shed almost 30 diplomatic missions, while its science and innovation network expanded its coverage from 24 to 28 countries.

Once the government’s eyes and ears abroad, embassies are now usually the slowest way to get information, unable to compete with lightning-fast media reporting and exhaustive country analyses prepared by NGOs and risk consultancies. The digitally connected world allows governments to communicate directly with their counterparts, and some world leaders, including Indian Prime Minister Narendra Modi, have become prodigious users of Twitter, Facebook, and Instagram, speaking to huge domestic and foreign audiences without even telling their embassies.

In some ways, smaller budgets have brought about some much-needed streamlining. In the five years since 2010, the United Kingdom’s Foreign & Commonwealth Office has been forced to shave off $143 million from its annual spending and nearly ten percent of its U.K.-based staff. But the agency’s leaner profile has required it to prioritize and shift resources from its largest European posts, as well as dwindling priorities in Afghanistan and Iraq, to address new crises in Ukraine and West Africa.

Australia, Canada, the Netherlands, Switzerland, and the United Kingdom are adapting to budget constraints by operating what are in effect joint embassies with other countries. Switzerland shares premises and operating costs with the Netherlands in Oman and with Austria in Los Angeles, California. Canada and the United Kingdom announced plans in 2012 for a number of resource-sharing arrangements, and Canada and Australia have already signed a reciprocal arrangement for representing each other’s interests in Asia, the Pacific, and the Americas. Under a 1986 memorandum of understanding, Canada and Australia agreed to provide citizens of the other country with consular assistance: helping those who are arrested, ill, or hospitalized; aiding victims of crime; and locating missing family members, among other tasks. They also, importantly, cooperate in crisis response, which is an increasingly significant focus of international exchange between ministries of foreign affairs the world over.

But the biggest threat to the viability of embassies is security. In conflict-ridden countries where information on the ground is scarce, diplomatic posts are crucial, and yet are routinely shuttered when conditions get rough. Most nations have closed their embassies in Libya, Syria, and Yemen because of the conflicts there. Even in less dangerous countries, embassies are mired in security protocols that restrict access by locals and often confine embassy staff and diplomats to semi-safe green zones—hardly a way to get an accurate picture of events on the ground. Indeed, some embassies, particularly American ones, resemble elaborate military bunkers more than diplomatic outposts. They are outfitted with bomb-proof pads and full-service food courts. Of course, these are still the exception. At most embassies, diplomats are free to go about their business, cultivating networks and pursuing their nations’ interests.

All of this doesn’t mean that embassies do not have a significant role to play in foreign relations. There are plenty of reasons why we still need these foreign outposts. They are their nations’ shop fronts: a physical interface between the home nation and the host country. Good diplomats forge relationships with governments that would otherwise be tough to reach; they navigate local power dynamics, gather and interpret information, help businesses steer through foreign legislation, and connect with local civil society. Tom Fletcher, U.K. ambassador to Lebanon between 2011 and 2015, confronted a society riven with dysfunctional politics and facing threats at its borders. Yet under his ambassadorship, the United Kingdom helped Lebanon defend its borders and stave off terrorist attacks and supplied vehicles and military infrastructure. Fletcher’s charisma and energy on the ground enabled the United Kingdom to build a stronger and more resilient presence in Lebanon and in the region. On the flip side, the absence of an embassy can be as damaging as its presence can be enabling. The United States’ absence from Tehran for over 30 years certainly made it more difficult for U.S. policymakers to parse developments in that notoriously complex country. And the closure of diplomatic posts in other war zones in the Middle East has severe consequences: it strangles the delivery of humanitarian assistance to populations, hampers support for besieged governments, and makes counterterrorism efforts far harder to implement.

But to survive, embassies will need to adapt.

State Department apartments complete with bullet-proof glass windows stand inside the compound of the U.S. embassy in Baghdad, December 14, 2011. Lucas Jackson / Reuters

They could begin by focusing more on adding value to their government’s understanding of a foreign country. Embassies cannot compete with the speed of news organizations and social media, nor should they try to. But they do provide a unique lens for such information, contextualizing and analyzing events with a trained eye toward enhancing their country’s national interest. What a media organization might find newsworthy will be different from what a diplomat judges as an important development for relations between his country and a host nation.

Diversifying embassy workforces will also help. Roughly 60 percent of senior leadership positions in the U.S. State Department, the U.K. Foreign & Commonwealth Office, and Australia’s Department of Foreign Affairs and Trade are held by men. This imbalance limits a nation’s understanding of and engagement with a foreign culture as a whole. Diplomats from a broader spectrum of backgrounds will be able to interact with more diverse segments of society.

Embassies also need to strike a better balance between security concerns and the ability of diplomats to do their job. This is a formidable issue and the consequences of neglecting it are extremely serious, as the deaths of Ambassador Christopher Stevens and others at the U.S. embassy in Benghazi have shown. But if embassies respond to security threats by cutting themselves off from the societies in which they operate, they might as well turn off the lights and go home. Harnessing new technologies, particularly social media, can help alleviate the impact of cumbersome security restrictions, although it’s a poor substitute for building strong personal connections with locals. Some embassies and diplomats are well versed on this, but they are the exception rather than the rule.

Without embassies, building and maintaining useful relationships with other countries would be much harder. There would be no dedicated agency establishing high-level relationships with foreign governments, garnering crucial knowledge about foreign institutions and legislative regimes, or smoothing the path for citizens and businesses in foreign markets. There would be no diplomats to understand local conditions and identify key players. There would be no consular experts trained to help their nationals in distress. Without embassies, crisis response, which relies on established relations with local authorities, would be less effective.

These are among the many reasons why most nations still see the value in having embassies. But whether their numbers dwindle further in the next decade will depend to a large extent on whether embassies can become more nimble and adapt to an increasingly fluid global environment. For a centuries-old institution, that’s not going to be easy.