Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Another one is making any sort of external web request; you should never use your web server to do this.


It depends on the use-case. You may want the request to your web server to wait for a response from your transaction processor (e.g. Stripe) before returning.


That shouldn't be done in a web request. Not only can it lead to wasted time in the request handler, but it can lead to race conditions like double purchases.


> it can lead to race conditions like double purchases

"Let's return as soon as possible rather than blocking" is not the real way to handle race conditions. All you are doing is reducing the surface (time) that such a thing can happen in. It makes more sense to plan these things out using something else (e.g. locking).


How do you implement "no really, this request should not return until the server has successfully completed external communication"?

You can do some sort of websocket-y mechanism to tell the client that the server has completed a previous request, or polling, but both of those bring a lot of infrastructure overhead.


Polling is super easy. It's just one more API endpoint.


Blocking is even easier, it's zero more endpoints.


Yeah and if Stripe goes down your server goes down with it.


How are you architecting things that an upstream error will cause your server to die?

Look, in both cases, the request needs to be synchronous. You need to tell the customer that their purchase went through. If you're going to add a whole other bus into the thing and make it asynchronous and have an elaborate polling solution on the client, that's fine, but I would (and do) just have them wait the two extra seconds and either say "your card has been charged" or handle the rare case with "there has been an upstream error, please don't close this window while we retry the request".


If Stripe is your payment processor, how do you propose that one should process payments if Stripe is down? How does making payment processing asynchronous help? Why would your entire server die because Stripe's API failed to return?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: