Thank you for reply.
I realize this is not an easy question, gives me headache to think
about the best way to implement it.
The flow of login/signup in my app is probably very common: after user
signsup with oauth,
I get user data, pass it to createAccount() method which just records
the user data into the database
and if user with the same twitter id already exists it will just
update the record.
This is easy part, can either user REPLACE INTO (mysql only)
Or test if userid exists then do insert or update.

So basically on signin with Twitter I alwasy get the fresh data and
update the record.

But then I set the unique cookie that is tied to twitter ID and then
can login user by cookie. This is where I cannot decide what to do:
I can just get the record from database using this unique cookie and
use it as user data. This will be the fastest way to create
the viewer object but the data is not fresh. What if user has updated
his profile in Twitter, then he will see an outdated description,
possibly outdated links, etc.

So the solution is to login by cookie this way: get record from DB
based on cookie. Use the user's token, secret from that record and get
the fresh data, update the record in DB. Basically a full
synchronization of record in every login by cookie (in every repeat
visit to site)

This may add too much load to the database and network, especially if
thousands of users come to the site  suddenly.

Maybe there is another middle ground solution - get the data from
Twitter via cache system, so if record exists in cache, use it, if
not, get data from Twitter API and put in cache for 24 hours. This way
data will not be always fresh, but will at least be guaranteed to be
not older than 24 hours.

On Feb 18, 3:01 am, Dave Sherohman <> wrote:
> On Wed, Feb 17, 2010 at 05:52:28PM -0800, Dmitri Snytkine wrote:
> > I have 2 choices: store the data in the database and put cookie in
> > user's browser and next time user visits, I can just pull the
> > username, name, etc from my database
> > Or I can use user's access token/secret that I also store in database
> > to get the fresh data from Twitter.
> > Getting fresh data will guarantee that I have user's latest color
> > settings, background, avatar, description
> > But I may run over 150 requests per hour very easily.
> > How is this usually done by other app developers? What's the best
> > practice for synchronizing user's settings with Twitter?
> The way I'm doing it on FishTwits is to cache the most recent profile
> data for each user.  So I'm basically doing your first option (store it
> in the database), but refreshing it with the latest fresh profile data
> whenever I send or retrieve a status update for the user - that
> information is already coming back with the status, so I can update it
> without having to wait for any extra requests to complete.
> --
> Dave Sherohman

Reply via email to