There is no perfect answer for this question and all depends on details.
As a first 'defense line' I would try to avoid such situations at all, by simply not selling out articles that low if any possible. If this is possible may depend on the situation and the kind of articles you want to sell. In the company I work, articles are mostly removed from the website before we run out of stock. But we are selling whole sale and the few remaining articles are sold by our sales people as special offers. This may not be an option for small shops, especially when selling high priced articles.
The solution to do the double check when adding something to the basket isn't very good. People put a lot in baskets without ever actually placing an order. So this may block this article for a certain period of time.
So in my humble opinion for small jobs the best way is to do a final check right before the payment, when the order is actually placed. In worst case you have to tell you customer that you where running out of stock right now (what for small shops will not happen that often).