Marks & Spencer Group Plc and online delivery startup Ocado Group Plc are discussing a joint venture that would hitch the fortunes of a struggling U.K. retailer to one of the country’s biggest tech success stories.

Shares of both companies surged after they confirmed talks on a deal to expand Marks & Spencer’s lagging home-delivery operations and boost its food business. An agreement would free Ocado to focus on licensing its automated warehouse technology to supermarkets, a business that’s growing faster than its U.K. grocery operation.

If the companies reach an accord, Marks & Spencer could succeed John Lewis Partnership Plc’s Waitrose as Ocado’s grocery supplier. M&S intends to pay Ocado about 800 million to 900 million pounds ($1.1 billion to $1.2 billion) for a 50 percent stake in the venture, according to a person familiar with the matter.

M&S has been slower to move into home delivery than other grocers in Britain, where the Brexit-hit pound has squeezed profit margins. Online giant Inc. and discounters such as Lidl and Aldi are also challenging the big, established companies like Tesco Plc and J Sainsbury Plc, which has responded with a deal for Walmart Inc.’s Asda that faces growing regulatory opposition.

Ocado, founded by former Goldman Sachs banker Tim Steiner, has grown into one of Britain’s most celebrated tech companies. After a slow start for its licensing business, the company has struck deals with U.S. grocer Kroger Co., France’s Casino Guichard-Perrachon SA and others.

An agreement with Marks & Spencer would be broader than those deals, which are focused on the use of its technology. The licensing arrangements have given Ocado opportunities in areas where online shopping has grown more slowly than in the U.K., one of the most advanced e-commerce markets.

“This would give Ocado more time and resources to invest and develop the technology side of the business while retaining some interest on the retail side,” said Dusan Milosavljevic, an analyst at Berenberg in London. “It means they can focus more on selling their technology.”

Ocado rose as much as 13 percent, the most since June, while M&S was up as much as 4.3 percent in London. There’s no certainty the talks will result in a deal, Marks & Spencer and Ocado said in separate statements.

By offering home delivery via Ocado, M&S could reach a wider customer base in the U.K., potentially creating a greater challenge to mainstream grocers. The retailer’s large stores in city centers and shopping malls, offering food and clothing, have struggled to compete with e-commerce alternatives, while its convenience food shops offering sandwiches and prepared dinners have fared better.

Until recently, M&S’s grocery arm served as an engine of growth, with the apparel operations in a long decline. But performance has waned in recent quarters, prompting Chairman Archie Norman to step up cost-cutting. The company is moving to close 100 stores across Britain.

Expanding in e-commerce also carries risks, because many supermarket chains lose money on their online operations. M&S, with higher prices and a smaller product offering than most other U.K. grocers, could have a hard time making the numbers add up.

“No one makes money from retailing food online, and M&S already makes very thin margins through selling food so I struggle to see the commercial logic,” Richard Hyman, an independent retail consultant, said by phone.

Ocado is also looking to bounce back from a major setback earlier this month when a fire destroyed one of its automated warehouses, where robots pick groceries from thousands of crates to prepare customer orders for delivery. Revenue growth will suffer until capacity can be increased elsewhere, the company has said.