Jun 26, 2011

Finally -- Redis

I have been playing around with Redis for a couple days.

Finally, I got a design that works very well and very fast.

This is the general design when using Redis.

For example, if we have post, which has fields: title, created_date, user_id.

We can store it like this

post:$id:title --> "Example Title"
post:$id:created_date --> "2011-10-10"
post:$id:user_id --> 5

But when you want to query it, please use mget .

You will get the result at once.

Redis has a big problem with network latency and we can use mget to minimize the number of queries.

Jun 21, 2011

Jun 15, 2011

Auto-login-after-action architecture

We should always create a pending table:

[data, status, unique_key]

The column 'data' is for all the necessary data for an action encoded in JSON.
The column 'status' is for checking if it is done or not.
The column 'unique_key' is to identify the returning user.

With this way, the pending table is independent from the action table.

Top of the week architecture

I have come up with an architecture which is quite ok.

First, we shall have a table:

[guid, date, hour, entity_id, score]

The column 'guid' is the primary key of the table, which is 'date' concatenated with 'hour'.

When the score is incremented or decremented, we also update this table. Here is the crucial technique for updating:


INSERT INTO `hour_counts` (`guid`,`date`,`hour`,`entity_id`,`score`) VALUES ('#{guid}','#{time}','#{hour}','#{entity_id}','#{score}') ON DUPLICATE KEY UPDATE `score`=`score` + 1;


With this SQL statement, the record is automatically created if it is not there. If it is there, then we just increment the score.

Since MySQL handles concurrency for us, we can be sure that there is no duplicate record.

That is pretty cool.

Jun 14, 2011

Do not build a website that solves a specific task.

Your market will be too small, and nobody will come to use your website.

This is a lesson learned from CollegeSwap. The market is too small and it is so specific that nobody comes to use it.

Well, of course, build it if your marketing plan is a very clever one.

Lesson from FriendMage

Never ever create anything, any website, or any software:

you do not feel passion about.

OR

you haven't been used similar websites for a long time

OR

It involves too many skill sets, which are out of your leagues.

The reason is simple. It it because you will not maintain it and you will not improve it. More importantly, you will not know what to be improved, really.

Jun 10, 2011

People do not like to login



This is a proof that people do not like to login. Or they do not like to explicitly press the login button.

You can see that the yellow line is peaked at 5:00. That point is the number of guests who tried to post comments, but it failed though because they have to login before posting comments.

At 6:00 and 7:00, the comment box is hidden for ones who haven't logged in.

We can see that the red line is still the same. (The red line is the number of comments posted by members)

The conclusion is that when we force people to login before posting comments, they just leave!