I don't think lack of space is the issue. Combinis are everywhere but you'll still see vending machines in most parking lots and laundromats.
Tech advancement is also relevant. I believe Japan invented vending machines that serve hot and cold drinks simultaneously and they adjust with the seasons. They invented improved ways of loading the cans and spend a lot of effot on the design and art, there are even vending machine exclusive drinks etc.
But they also have a lot of staffed convenience stores (typically 7-Eleven) that are generally better than the random chain convenience store in the US (often in a gas station).
Don't know the history.
Having lots of vending machines even for simple things like bottled water and soft drinks reduces the pressure on the convenience stores quite a bit. More advanced vending machines with other products helps even more.
I wonder if it's cultural. For instance I always hear how Japan has a lot of vending machines and am wondering if it's just pure tech advancement and efficiency at work, maybe lack of space to open a proper kiosk with a seller, or there is a cultural element of not wanting to "inconvenience" others having to interact with them.