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 8279577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:23:11+00:00 2026-06-08T09:23:11+00:00

I implemented social-network-like notification, using long-polling with nodeJs database, I’m using redis and cassandra

  • 0

I implemented social-network-like notification, using long-polling with nodeJs

database, I’m using redis and cassandra

I saved a timestamp as “user_read” in redis

everytime users read the notifications, I refresh the “user_read”

when database got notifications timestamp larger than “user_read”

I will respond them to users

my code is like this

function(req, res){
longPoll()
function longPoll(){
    async.waterfall([
         connectDB,
         getNotification             
],function(err,data){
    if(there's no notification timestamp larger than user_read){
          setTimeout(longPoll, 1000);
    }else if(there's new data){
          res.json(data);
    }

    if(con)
       con.close();
})
}
};

here’s my question:

  1. I’m using setTimeout here, is it appropiate? maybe use nextTick, or setInterval?
  2. should I close the connection everytime after I query from DB, or just one time when I respond?
  3. I want to optimize, and optimize suggestion?
  • 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-08T09:23:12+00:00Added an answer on June 8, 2026 at 9:23 am

    It depends, nextTick is usually more adequate, but think of it from a different perspective, basically you’re “short-polling” the DB every second for every user who is connected to your long-poll.

    So even if your webserver isn’t getting unnecessary polls because of long-polling (btw, is there an exit condition for that with empty answer as well at you?) you’re still short-polling the database.

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

Sidebar

Related Questions

I'd like to implement a social network for students and teachers. I just can't
I have a simple social network project going and I would like to add
Implemented a new feature on the site as if it were a social network.
I want to implement authorization using social networks like twitter, facebook, Linked In. How
I'm currently developing a community (like a lightweight social network) for a limited (local)
I'm working on a Rails app that implements some social network features as relationships,
I implemented the exception filter like here: http://www.asp.net/web-api/overview/web-api-routing-and-actions/exception-handling And registered it globally, like microsoft
I implemented my project for notification. I tested it in development Provisioning Profile (development
I implemented class that serves as TcpCLient server. Looks like this: { [Export] public
I am in the middle of making a social network, and i want it

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.