Of the many institutions suffering through the world’s metamorphosis from analog to digital (real to virtual, offline to online), few are as beleaguered as that bedrock of our culture, the public library. Budgets are being slashed by state and local governments. Even the best libraries are cutting staff and hours. Their information desks are seemingly superseded by Google, their encyclopedias are gathering dust. And their defining product, the one that lines their shelves, now arrives in the form of a weightless doppelgänger that doesn’t require shelves.

In the technocracy, all the world’s information comes to us on screens—desk, pocket, wrist, goggles—and no one trudges through wind and rain with library card in hand to find a single worn object. After all, when you want the text of Magna Carta, you don’t track down the original. Same with books? “Libraries are screwed,” said Eli Neiburger, a Michigan library director, in a much-quoted presentation at a Library Journal conference in 2010. “Libraries are screwed because we are invested in the codex, and the codex has become outmoded.”

So is the library, storehouse and lender of books, as anachronistic as the record store, the telephone booth, and the Playboy centerfold? Perversely, the most popular service at some libraries has become free Internet access. People wait in line for terminals that will let them play solitaire and Minecraft, and librarians provide coffee. Other patrons stay in their cars outside just to use the Wi-Fi. No one can be happy with a situation that reduces the library to a Starbucks wannabe.

Perhaps worst of all: the “bookless library” is now a thing. You can look it up in Wikipedia.

I’m an optimist. I think the pessimists and the worriers—and this includes some librarians—are taking their eyes off the ball. The library has no future as yet another Internet node, but neither will it relax into retirement as an antiquarian warehouse. Until our digital souls depart our bodies for good and float away into the cloud, we retain part citizenship in the physical world, where we still need books, microfilm, diaries and letters, maps and manuscripts, and the experts who know how to find, organize, and share them.

In the midst of an information explosion, librarians are still the most versatile information specialists we have. And the purest. In his new book, BiblioTech, a wise and passionate manifesto, John Palfrey reminds us that the library is the last free space for the gathering and sharing of knowledge: “Our attention cannot be bought and sold in a library.” As a tradition barely a century and a half old in the United States, it gives physical form to the principle that public access to knowledge is the foundation of democracy.

The problem of libraries now—and it is a problem—involves some paradoxes, which need to be sorted out. For one thing, as Palfrey says, librarians will need to cherish their special talent as “stewards” while letting go of the instinct to be “collectors.” Knowledge in physical form needs to be handled carefully, preserved, and curated. But with digital information pouring into iPhones and Kindles in petabytes—via Twitter and Instagram and YouTube, not to mention Amazon’s self-publishing factories—libraries need to rethink old habits. They cannot collect everything, or even a small fraction of everything. “That model is already too hard to keep up,” Palfrey says. “A network of stewards can accomplish vastly more than a disconnected (even sometimes competitive) group of collectors ever can.”

The packrat instinct is hard to shed. Five years ago the Library of Congress began a project that collects every utterance on Twitter, in the name of preserving the nation’s digital heritage. That is billions weekly, sucked up for storage in secure tape archives, and the Library has yet to figure out how to make any of it available to researchers. Divorced from a human curator, the unfiltered mass of Twitter may as well be a garbage heap. Meanwhile, onward streams the continually vanishing conversation in Facebook and Snapchat and whatever next year’s channels will be, along with the email of the great and small, preserved haphazardly or not at all, to the presumed dismay of future historians. What’s an archivist to do?

There is no escaping the tension between real and virtual space, between the shelf and the cloud. “Librarians well know that the discovery of information is moving out of physical locations and into distributed spaces”—i.e. screens everywhere—says Palfrey, and this is an understatement. He recalls an afternoon in his town library in Andover, Massachusetts, when he heard a thirteen-year-old shouting into his iPhone, “Siri, what does ‘terminal velocity’ mean?” Evidently the feckless genius of the cloud had nothing to offer. Palfrey took comfort from that, knowing that any reference librarian could do better: “I realized that all will be well in the world of libraries, at least for a while.”

Alas—all too predictably—in the time it took for Palfrey’s book to reach physical form, Siri has mastered terminal velocity. Wikipedia continues to evolve, the one great holdout from the commercial Internet, refusing to charge money or sell its users’ information, crowd-sourcing the expertise of a thousand reference librarians. It is an effective online realization of the vision of a network of stewards. Still, it is not and does not aspire to be a library.

People continue to gather in libraries, with or without their laptops and pocket devices. They sit at the old wooden tables and consult real documents and cherish the quiet aura of the books that surround them. Is this merely a nostalgic dream? Palfrey is technologically savvy and looking toward the future, and the fundamental point applies: “In a digital era, spaces where people can come to study, read, and think are essential for communities and individuals to thrive. We already have too few such open, public spaces.” The library remains a sacred place for secular folk.

The toughest question for libraries may be what to do about e-books. Libraries want them, naturally—to have them and to lend them. If e-books are off limits, Palfrey says, “the essential role for libraries of providing free access to culture to those who cannot otherwise afford it is in peril.” Then again, a library that streams e-books risks rendering its brick-and-mortar space superfluous. And a library that could lend any e-book, without restriction, en masse, would be the perfect fatal competitor to bookstores and authors hoping to sell e-books for money. Something will have to give. Palfrey suggests that Congress could create “a compulsory license system to cover digital lending through libraries,” allowing for payment of fair royalties to the authors. Many countries, including most of Europe, have public lending right programs for this purpose.

Palfrey, now head of school at Phillips Academy, is a former Harvard law professor and executive director of the Berkman Center for Internet and Society. He is also founding chairman of the Digital Public Library of America, and BiblioTech serves in part as a brief for that project. The DPLA has been described in The New York Review by Robert Darnton; it began in reaction to Google’s project to digitize all the world’s books on its own terms, for its own use. The DPLA is meant to be a free and public online library, combining the resources of the largest university archives with collections from regional libraries and museums—as Palfrey says, “a national library platform for the United States—and in some respects the whole world—in the digital age.”

The tensions bedeviling every public library apply to the DPLA as well. It is “free to all” and open source and therefore unable so far to include copyrighted material; and it has to be careful of competing with the myriad small institutions that are aggregating its resources. On the one hand the DPLA is a website, http://dp.la. On the other hand, as Palfrey explains, it must serve broadly as a platform, encouraging librarians to use their expertise to link regional and national collections and create timely exhibitions. The balance will not be easy to find. Websites like to attract visitors, the more the better, and so digital services lean toward centralization.

Librarians will have to embrace these contradictions, and so will all of us who cherish libraries. A transition to the digital can’t mean shrugging off the worldly embodiments of knowledge, delicate manuscripts and fading photographs and old-fashioned books of paper and glue. To treat those as quaint objects of nostalgia is the technocrats’ folly. The masters of Internet commerce—Google, Facebook, Amazon, Apple—sometimes talk as though they’re building a new society, where knowledge is light-speed and fungible, but a marketplace is not a society.

John Palfrey’s BiblioTech is published by Basic Books.