When to use Stateful and Stateless sessions in drools?

76 views
Skip to first unread message

Nilima Gawade

unread,
Apr 6, 2025, 2:36:25 AMApr 6
to Drools Usage
When to use Stateful and Stateless sessions in drools? How to use it in Microservices Architecture?

Toshiya Kobayashi

unread,
Apr 8, 2025, 4:56:33 AMApr 8
to Drools Usage
If an application (or a REST endpoint) recieves a request, evaluates it with drools and send a response, so it doesn't need to maintain drools session state, you can use a stateless session.

If an application (or a REST endpoint) recieves multiple requests and evaluates them together with drools, so it needs to maintain drools session state across requests, you need to use a stateful session.

Stateless session is recommended if possible, because it's easier to manage.

Microservices Architecture is generally based on stateless architecture, so stateless session.

Toshiya

2025年4月6日日曜日 15:36:25 UTC+9 nilima...@ebixcash.com:

Nilima Gawade

unread,
Apr 9, 2025, 1:46:32 AMApr 9
to drools...@googlegroups.com
Thank you Toshiya.

Any thoughts on how to handle large data sets in case of of stateless session in microservices?



--
You received this message because you are subscribed to the Google Groups "Drools Usage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-usage...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/drools-usage/7b249238-21fd-4a5d-954c-f4132f055f3cn%40googlegroups.com.

Confidential: The information contained in this e-mail and any accompanying documents may contain information that is confidential or otherwise protected from disclosure. If you are not the intended recipient of this message, please immediately alert the sender by reply e-mail and then delete this message. Any dissemination, distribution or other use of the contents of this message by anyone other than the intended recipient is strictly prohibited. We have taken every reasonable precaution to minimize the risk but is not liable for any damage you may sustain as a result of any virus in this e-mail. You should carry out your own virus checks before opening the e-mail or attachment. “

Toshiya Kobayashi

unread,
Apr 11, 2025, 3:17:46 AMApr 11
to Drools Usage
> Any thoughts on how to handle large data sets in case of of stateless session in microservices?

Could you provide some more details? (e.g. One request has too large data which causes OutOfMemory. or Many concurrent requests etc.)


2025年4月9日水曜日 14:46:32 UTC+9 nilima...@ebixcash.com:

Nilima Gawade

unread,
Apr 14, 2025, 6:14:41 AMApr 14
to drools...@googlegroups.com
1.If there are many concurrent requests?
2.Same rule will execute for say 1 million accounts lets say.

Thanks,
Nilima

Toshiya Kobayashi

unread,
Apr 16, 2025, 12:36:01 AMApr 16
to Drools Usage
> 1.If there are many concurrent requests?

In stateless use case, each request is isolated, so you can easily scale your microservice (e.g. increase pods) depending on the load.


> 2.Same rule will execute for say 1 million accounts lets say.

It would be the same as the above case.

Cheers,
Toshiya

2025年4月14日月曜日 19:14:41 UTC+9 nilima...@ebixcash.com:

Steven Chou

unread,
Apr 24, 2025, 2:27:48 PMApr 24
to Drools Usage
Hi Toshiya,

When using the Rule Unit API, does it use Stateless or Stateful KIE session under the hood?

Thanks,

Steven
toshiyak...@gmail.com 在 2025年4月15日 星期二晚上9:36:01 [UTC-7] 的信中寫道:

Ajay Chowdary Kandula

unread,
Apr 24, 2025, 3:11:50 PMApr 24
to drools...@googlegroups.com
• Rule Unit API uses a stateful KIE session model under the hood.
• It is designed for scenarios where rules need to react to changes in data over time, maintaining state and supporting inference, which are core features of stateful sessions.


If you need stateless, function-like rule execution, use the traditional `StatelessKieSession`. For encapsulated, stateful business logic, use Rule Units.


Thanks and Regards!!!
Ajay C. Kandula


Toshiya Kobayashi

unread,
May 7, 2025, 4:22:02 AMMay 7
to Drools Usage
> When using the Rule Unit API, does it use Stateless or Stateful KIE session under the hood?

RuleUnitInstance is not exactly the same as StatefulKieSession, but similar to StatefulKieSession. You need to call "close" for RuleUnitInstance when your work is done.

If you close a RuleUnitInstance on every request, it would work as the same as the stateless use case.

2025年4月25日金曜日 3:27:48 UTC+9 chouc...@gmail.com:
Reply all
Reply to author
Forward
0 new messages