views:

38

answers:

1

I recently inherited an e-commerce app (Java/Struts) that I'm porting to Rails.

The thing is, we frequently have to do forensics on orders by poring through the log files, and with the old app's logs (log4j wall of text) it's pretty hard to make sense of the individual orders when several people are placing orders simultaneously.

So I'm soliciting advice on a good strategy for logging of these orders, like maybe logging each individual order to its own MongoDB collection based on unique cart ID? Or maybe group them by IP address? Something different entirely?

Essentially, what is the best approach for logging of an online store so that it's easy to backtrace each user's interaction with the site?

+2  A: 

You shouldn't log each order to its own collection, as collections incur too much overhead. I'd have a single collection containing all interactions. The decide if you want to store one or multiple documents per order. If you store just one document per order, that document can contain an array of 'interaction' documents. It's easy to push another interaction onto each document.

If you're going to do lots of slicing and dicing of interactions, then I'd say one document per action, adding the appropriate indexes for the kinds of queries you'll be doing.

Kyle Banker