Should I maintain separate database for my data?

I’m learning about Temporal and I’m trying to understand how should I design the whole system with Temporal.

So let’s say I have some system where customer makes an order with some data and manager should confirm an order.

This system will have backend component which will handle HTTP requests from the user.

After customer made an order, new Temporal workflow will be started.

Now manager opens some kind of UI to find out about pending orders. So I have to query orders and its statuses from the backend in some way.

I can see two ways of implementing it:

  1. Maintain a separate database for orders. Temporal workflow will use activities to insert/update data in this database. Backend just uses this database. For example there could be “status” column which will reflect order status, so I can select all orders with PENDING status or something like that.

  2. Use Visibility/Query API. It’s my understanding that Temporal workflows are persisted in the Temporal database, so I can just take advantage of it and query Temporal for all the data I need.

So basically my question is: should I build my system around Temporal or should I build my system around separate database and just use Temporal to update this database as necessary?

My initial reaction was to choose #1. However Query API was added for a reason, I guess. Or is it just some kind of escape hatch which should not be used often?

1 Like

Great question! The answer is as usual - it depends.

Temporal workflows are stateful, so all the data related to the process of fulfilling an order doesn’t need to be stored in a separate database. However, Temporal doesn’t have advanced querying capabilities across multiple workflows. So listing orders, especially ones that were closed last year, is not something it can provide. Also, Temporal is not a storage for other data like customer address, payment information, etc.

My mental model is that workflow should be queried directly for the current state of an order while it is open. The DB is used to list and search for specific orders and maintain historical information. You never want workflows polling DB for some state field.

2 Likes