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

前端 未结 3 1804
天命终不由人
天命终不由人 2020-12-07 02:01

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

3条回答
  •  被撕碎了的回忆
    2020-12-07 02:03

    Here are some reasons I can think of:

    1. The cost of maintaining state will have to be borne server side only - service consumers are rarely web browsers, so have no cookies. This brings down your server performance and increases your design complexity.

    2. A service consumer is an intelligent program, rather than a dumb browser. As such the program will (almost always) maintain its own state. In other words, when you provide a service, your consumer will request precisely the data it wants. Maintaining state on the server becomes obsolete and unnecessary.

    3. Transactions - a service is a dangling point in your system because its clients are mostly intelligent, and they decide when to inform you of changes in their state. This means that if you maintain state, you might have to wait between service calls to finish a transactional operation. And there's absolutely no guarantee the client will ever make that next service call.

    There are a lot of reasons, but these are the ones I can think of off the top of my head :)

提交回复
热议问题