You get working capital from an external source like a bank or a moneylender. The external source gives you cash to buy raw materials and process them now. In the future, you sell finishhed goods and return the original cash along with interest.
Coffee works the same way. It gives you wakefulness immediately so that you can do whatever you have to do. Once it wears off, you sleep for all the time you stayed awake instead, plus a little bit extra (which represents the interest).
Not only that, both also keep you running on a daily basis, and are essential to the continuing existence of civilization as we know it.