aknEvrnky's avatar

best way to store guest users' data

Hi folks, currently I'm working on an e-commerce project. I need to store non signed in people's data such as Cart products, address, etc. My current workflow is like this:

Whenever user adds an item to basket, save it to cookie with base64 encoded. User may enter address and sender informations. Get cookie, resolve it, and merge it with new data. then store it in cookie with bas64 again.

It currently works fine. But if user adds more products to basket, this increases cookie size and after a while nginx throws 502 bad gateway error.

What is the most appropriate solution for my case?

0 likes
2 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@aknevrnky There are a few ways to store guest user data that may be more appropriate for your use case:

  • Database storage: Instead of storing data in cookies, you can store the data in a database. This will allow you to store more data and avoid any issues with cookie size limits. You can use a unique identifier, such as a session ID, to link the data to a specific guest user.

  • Local storage: Another option is to use local storage, which is similar to cookies but can store more data. Local storage data is stored in the browser, so it's not sent with each request, which can help to improve performance.

  • Server-side session: A server-side session is another option for storing guest user data. It's similar to database storage, but the data is stored on the server, rather than in a database. This can be more secure than storing data in a cookie or local storage, as the data is not accessible from the client-side.

  • Using a third-party service: You could use a third-party service such as Firebase or AWS to store the data. This will allow you to easily scale and handle large amounts of data.

Ultimately, the best solution will depend on the specific requirements of your e-commerce project, and the trade-offs between security, scalability, and performance that you're willing to make.

2 likes
aknEvrnky's avatar

@tisuchi thanks for suggestions. I'll use laravel's session db driver. It'll be more secure and reliable for me. But I've a question. When time sessions will be expired that are stored in db? Should I set a scheduled task or laravel handles it automatically?

Please or to participate in this conversation.