Most people don’t buy a jar of relish every week. But when they decide to buy one from Ocado—the world’s largest online-only grocery retailer—they don’t have to scrabble at the back of the store. Instead, they call on robots and artificial intelligence to have it delivered to their door.

Ocado claims that its 350,000-square-foot warehouse in Dordon, near the U.K.’s second city of Birmingham, is more heavily automated than Amazon’s warehouse facilities. The company’s task is certainly more challenging in many respects: most of the 48,000 lines of goods that it sells are perishable, and many must be chilled or frozen. Some, such as sushi, must be delivered on the same day they arrive in the warehouse.

That turns storing, picking, and shipping items into a complex, time-constrained optimization problem. But in order for Ocado to grow and turn a profit—which it does, despite a crowded U.K. grocery market—it has to make every step as efficient as possible.

Currently, when a customer orders groceries via Ocado’s website, large plastic crates are swiftly filled. The containers are packed by hand, but little legwork is required: 30 kilometers of conveyor belts at the Dordon warehouse carry empty boxes straight to people who work as pickers. They grab items from shelves that are replenished by robots, or from boxes brought out of storage via cranes and conveyors. Ocado’s algorithms monitor demand for products and use the information to map out an optimal storage scheme, so that popular items are always within easy reach.

Once an order is packed, it’s hauled off in a large truck and taken to a distribution center to be loaded into a van. Each van then embarks on a delivery route that can be carefully optimized according to factors such as customer time preferences, traffic, and even weather.

But Ocado wants to be faster. “Fractions of a second in our business count,” says Paul Clarke, Ocado’s chief technology officer. “It's all about how we can shave the next little bit off our process.”

So its third warehouse—currently in live trials near Andover, west of London—is being designed from scratch. Its main floor is laid out in giant grid about the size of a football field, split into washing-machine-size squares. Beneath each square is a vertical stack of five crates of groceries. On the surface of the grid are up to 1,000 robots, each able to lift crates from below.

The robots scuttle around, passing within centimeters of each other, at up to nine miles per hour. Orders relayed via a specially designed 4G network instruct the robots to grab crates and shuttle them to the edge of the grid, where pickers can grab the needed products. The robots work as a swarm: if the required product is four crates down in a stack, say, several can remove boxes to open the way.

The Andover warehouse, which is likely to enter full service in 2017, is a trial for an even larger facility in Erith, just outside London, which will begin construction next year. Its storage area will be three times the size. That means working out where to store goods and retrieve them, using thousands of robots, is incredibly complex. Clarke says that the computational demands of this optimization problem are bearable, but he adds that the company is investing in GPU-based systems and keeping a watchful eye on quantum computing for the future.

Ocado is working on robotics that could one day pick orders from the crates carried by its swarm of robots, but that’s difficult, thanks to the wide variation in the shape of groceries—from, say, a bag of oranges to a bottle of wine. As a result, Clarke says, humans will be involved for the foreseeable future.

He’s similarly restrained about automation of the delivery process. While the company is already in discussions with the University of Oxford’s self-driving-vehicle spinout Oxbotica—though it won’t say about exactly what—Clarke says many customers will continue to prefer a human to deliver their order, even if autonomous vehicles make it possible for robots to take over the job.

Still, Ocado’s business is by nature one in which robots will ultimately be preferable to humans. When pushed on the impact of automation on employment, Clarke is bullish. He insists that it’s a “game that is going to play out regardless,” adding that “this is happening on a world stage … if we as a U.K. business don’t continue to get better using automation, somebody else will, and we’re determined not to let that happen.”

The customer experience, meanwhile, will benefit from AI systems being built by Ocado’s developers. “With more data comes greater intelligence—because that’s the food of machine learning,” says Clarke. The company uses machine learning to spot missing items in a shop, populate a basket of groceries on the basis of learned preferences, and even suggest versions of products that are lower in salt or sugar.

Over time, Ocado plans to streamline the ordering process as far as it possibly can. Clarke suggests that the company could acquire consumption data from your smart fridge, listen to what recipes you’re talking about via a smart assistant like Amazon’s Alexa, and even mine your calendar for data so it knows you’ll be cooking for friends next weekend. Ultimately, he says, it would like for “the right groceries to turn up, at the right time, as if by magic, without you even having to ask for them.”

It’s not the only company asking food shoppers to sacrifice anonymity for convenience. Amazon’s new Go convenience store, for instance, allows shoppers to scan their phone, pick up food from the shelf, and walk straight out, paying later because the company knows just what they took.

Still, if customers can stomach the loss of privacy, Ocado offers something valuable in return. “We can free people up,” says Clarke, “so that they have more time to experiment and experience the delight of food.”