tracking the shopping cart for an unregistered user

What is a good way to track the shopping cart for an unregistered user?
For a user session it is easy, but what if the user logs in, adds a few
items in the cart, and decides to terminate the session and then returns

What are some of the design trade-offs?

I would probably make that kind of session expire quickly and add a method to remove that from the db after a certain time period. I have a prod app that I am working on fora company that keeps the sessions in the db and we wrote a task that deletes all session older than like 90 days I think or something like that.

Hello Chris,
Thanks for the response. Yes it is a good idea to expire this kind of
session data.
My question was more about how to track an anonymous user across
sessions reliably. The only thing that I can think of is doing this
based on the IP address which can be unreliable? What if there are a
number of users coming via the same gateway working in the same office?
Appreciate your thoughts on this.

You could assign each session a random number for each one.

Semi-reliably: set a persistent cookie with the session/cart id.