Most local pet shops or clinics buy from wholesalers and add a markup to the price before selling it to you.
The online stores are supplied mainly by wholesalers or distributors who would buy in bulk and provide a good discount compared to offline market prices.
These distributors also have efficiencies in reducing the cost of running a retail store, as most of their inventory is sold online.
What we lose by buying online is - shipping or delivery time! If there is an urgency, you will walk to your local vet clinic or pet store to buy your pet supplies. However, if you plan correctly, most of the common meds like treatment for fleas/tick/worms must be repeated and purchased in advance, and some online stores also provide subscriptions.
For example, https://www.79pets.com is one such online pet supply store that has supplies from global warehouses in UK and Singapore and can provide the lowest price guarantee for products from top brands like NexGard and NexGard Spectra, HeartGard, Advocate, and many more.