IN THE beginning, the idea of Internet freedom was exhilarating. As one champion, Alec Ross, put it in a 2010 essay, the dream was frictionless communication between users, without interference by an intermediary, leading to the greatest free market for ideas and commerce in history. The reality is turning out to be far more complicated. The utopian dream is giving way to fiefdoms of interfering rules, blockages, filters, surveillance, national controls and privacy threats.

The recent announcement that Apple has signed a contract for its first data center in China raises again both the promise and peril of the digital era. Apple is complying with a new Chinese law requiring companies to store users’ data in the country. The data center in Guizhou, a province in southwest China, is a partnership with a local Internet services company. Apple, which derives 21 percent of its revenue from China, is not the first international tech company to do this; Amazon.com and Microsoft have also established data centers in China. (The chief executive and founder of Amazon, Jeffrey P. Bezos, owns The Post.) Nor is China the only country to demand “data localization,” a growing trend driven in part by a quest to improve performance and reliability, putting data physically closer to the users who need it.

The concern is the potential impact on freedom of expression. China often uses laws to punish those who speak their mind. Its leaders imprisoned Liu Xiaobo, a Nobel Peace Prize laureate who sought democracy, until his death; built a massive Great Firewall to keep Chinese users from seeing the digital world beyond; and every day attempt to squelch what people can say and read in social and news media.

Apple vows not to compromise its commitment to user privacy but also pledges to comply with local laws. What happens if China’s authorities demand data from the China-based iCloud? Apple says it and its local partner will comply with requests under Chinese law if they possess the data, which might include metadata of communications, photographs and emails. But two popular Apple services, iMessage and FaceTime, are end-to-end encrypted; Apple does not have the keys — the users do.

Apple’s presence in China can be a force for good. But it seems likely that China’s repressive system will pose painful choices for Apple and all the big tech companies that put their data on Chinese soil. Apple earlier complied with a government request to pull the New York Times from its China App Store. All the firms face a tension, a kind of gray zone, between the appeal of a vast market and its profits, and the Chinese people’s desire for information and contact with the world, all on one hand; and the prospect of becoming an accomplice to an authoritarian regime on the other. Tech titans that thrived in the liberal environment of abundant and guaranteed freedoms in the United States are now treading a path into the illiberal universe of arbitrary rule and dictatorship, and ought to walk very carefully.