Why is it bad programming to use a stateful webservice and why would it be allowed?

Justin Balvanz picture Justin Balvanz · Jun 12, 2009 · Viewed 7.2k times · Source

I have a need for a stateful webservice in our organization. However, everywhere I read online says that building a stateful webservice is bad programming but nothing ever says why. I guess I don't understand what is so bad about it. I also don't really understand why they would give a work around to allow you to have state in a webservice.

So I guess that my question is, why is it bad programming to use a stateful webservice and why would it be allowed?

Answer

NotMe picture NotMe · Jun 12, 2009

The whole purpose of a web service is to deliver a piece of functionality in one transaction in a way that is highly scalable. This means keeping things simple and atomic.

When you have to make multiple calls to perform the operation, you have a great potential of leaving transactions hanging. Is the client coming back? Are they done? How long should the transaction remain open? Did they crash? How should rollbacks be handled?

The answers to these questions could have a radical impact on the resources necessary to run your service. Which is why everyone recommends doing it all in one swoop.