开发者

Read vs Write tables database design

开发者 https://www.devze.com 2023-02-28 17:39 出处:网络
I have a user activity tracking log table where it logs all user activity as they occur. This is e开发者_如何转开发xtremely high write table due to the in depth tracking of click by click tracking. Up

I have a user activity tracking log table where it logs all user activity as they occur. This is e开发者_如何转开发xtremely high write table due to the in depth tracking of click by click tracking. Up to here the database design is perfect. Problem is the next step.

I need to output the data for the business folks + these people can query to fetch past activity data. Hence there is semi-medium to high read also. I do not like the idea of reading and writing from the same high traffic table.

So ideally I want to split the tables: The first one for quick writes (less to no fks), then copy that data over fully formatted & pulling in all the labels for the ids into a read table for reading use.

So questions:

1) Is this the best approach for me?

2) If i do keep 2 tables, how to keep them in sync? I cant copy the data to the read table instant as it writes to the write table - it will defeat the whole purpose of having seperate tables then, nor can i keep the read table to be old because the activity data tracked links with other user data like session_id, etc so if these IDs are not ready when their usecase calles for it the writes will fail.

I am using MySQL for user data and HBase for some large tables, with php codeignitor for my app.

Thanks.


Yes, having 2 separate tables is the best approach. I've had the same problem to solve a few months ago, though for a daemon-type application and not a website.

Eventually I ended up with 1 MEMORY table keeping "live" data which is inserted/updated/deleted on almost every event and another table that had duplicates of the live data rows, but without the unnecesary system columns - my history table, which was used for reading only per request.

The live table is only relevant to the running process, so I don't care if the contained data is lost due to a server failure - whatever data needs to be read later is already stored in the history table. So ... there's no problem in duplicating the data in the two tables - your goal is performance, not normalization.

0

精彩评论

暂无评论...
验证码 换一张
取 消