Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9145097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:25:46+00:00 2026-06-17T10:25:46+00:00

We have a messaging application that maintains an unread/read counter. Currently, we cache this

  • 0

We have a messaging application that maintains an unread/read counter. Currently, we cache this value for one hour, and if a user hits the app and the cache is expired, a count is done on the database tables to refresh the cached value.

The issue is when a high number of users come all at once and have expired caches, which is actually very common, this put tremendous strain on the db to do all the counts live and at the same time.

I would like to find a way to actively maintain this counter in the cache as we add or remove messages, so that the user is only ever hitting the cached value and it never expires. The new problem becomes making sure that count value stays in sync, as it’s possible that the systems that add or remove messages that would trigger a cache update might miss a couple, so the two numbers won’t be in sync anymore.

Some of the options I’ve come up with:

  • Doing a forced refresh every X updates. This is fine for active users, but less active users are more likely to have an inaccurate count, and with no cache expiry, that count remains for a long time.

  • Have a background job that updates the count. This has the problem that it is spending db resources on inactive users, which is inefficient and time consuming.

Does anyone have any general suggestions for this type of count maintenance?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:25:47+00:00Added an answer on June 17, 2026 at 10:25 am

    I’m not 100% sure of the application you have, but if I assume you have something like a mail client where you have number of received messages and number of sent messages, then I have some ideas:

    1. Check out the Thundering Herd idea for caching: http://en.wikipedia.org/wiki/Thundering_herd_problem The idea is that you don’t always use the same cache expiration value. Introduce some randomness. Some will expire in 1 hour, some in 58 minutes, some in 1 hour and 2 minutes. This prevents a lot of things from expiring at the same time.

    2. Consider invalidating the cache on the write side. In other words, let’s say I send a message to someone. When I send it in the UI, the code should go invalidate the other users cache (their received count just went up by 1) and then re-populate the value. In other words don’t just invalidate the cache with the one application call. Invalidate it and put the new value in cache pro-actively.

    3. You can seed the cache on a schedule, but like you said you’d be doing work that isn’t necessary.

    4. I’ve noticed a lot of large companies taking problems like this and pushing them out to the UI. You allow for slightly inconsistent data for a period of time, or you do little tricks. For example, when they send a message if you want it to “feel” fast, simply increment their “sent” counter by 1 with Javascript (assuming a web application) even if the counter hasn’t yet been saved to the database.

    In other words give instant feedback in the UI and fudge a bit and then asynchronously write the data and wait for it to finish the write/cache updates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that allows the user to send a picture. This picture
I currently have an application that has a messaging feature. It allows users to
We have an application that is essentially implementing its own messaging queue. When a
I have a client-server application that utilises MSMQ and NServiceBus for messaging. During some
I have a messaging system (very basic) that has a table like this: **MESSAGE_ID**
I am looking for a messaging/eventing framework that will allow changes in one application
I have created a class library (assembly) that provides messaging, email and sms. This
I have a PHP application that currently has 5k users and will keep increasing
I have been asked to prove that an SMS messaging application works properly by
I have a simple messaging application that gets the text of an editText box

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.