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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:09:33+00:00 2026-06-04T21:09:33+00:00

I have an app (for a given twitter user) that gets a list of

  • 0

I have an app (for a given twitter user) that gets a list of twitter users that you follow but don’t follow you back. It does this:

  • compare two lists, one from time x and time y, too see if more people followed you back or less.
  • See how long it took for twitter user x to follow you back.
  • See how many retweets/comments it took for user x to follow you back

The easy way I came up with is just a have a has-many belongs to relationship w/ a user and people not following you back, e.g.:

User table
-id

TwitterUser table
-user_id 
-timestamp
-isFollowing

So w/ that SQL schema I can get all the non-following back users for a given user and they can be compared by timestamp to match requirements above.

However, I was hoping that there was a better DB backend to represent this dataset than an sql database. I’ve been experimenting w/ redis but not sure how to pull it off.

I’m thinking maybe a document store – b/c all I want to do is take a diff of two data sets. Or more precisely: I want to diff two lists of twitter user ids.

Any ideas?

  • 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-04T21:09:34+00:00Added an answer on June 4, 2026 at 9:09 pm

    Bruteforce approach of comparing two arrays will have a time complexity of O(N*M), where N and M are sizes of arrays. So, we should instead store them using some intelligent data structure to do this efficiently.

    I’ve come up with the following approaches:

    1. List of twitter ids’ is a set because ids are unique. Redis supports
      sets and allows performing set operations like difference. Suppose
      you have 2 sets with the keys ids_at_time_x and ids_at_time_y.
      Add elements to them using SADD
      like this:

      SADD ids_at_time_x "15424"
      

      When you’re ready to perform a diff execute

      SDIFF ids_at_time_x ids_at_time_y
      

      This will return a list of ids from ids_at_time_x that are NOT
      present in ids_at_time_y. If you want to do reverse operation,
      i.e. retrieve a list of ids that are not present in ids_at_time_x,
      just swap arguments:

      SDIFF ids_at_time_y ids_at_time_x
      

      The best thing about SDIFF is that it operates very efficiently –
      time complexity is O(N) where N is the total number of elements in
      these 2 sets. Even if you do 2 diff operations, time complexity will
      still be linear.

    2. Store them as a sorted list. Redis supports sorted sets. When adding
      id you have to include a score of element (Redis will do sorting based on score) which equals to id in your
      case:

      ZADD ids_at_time_x 15424 "15424"
      

      When lists are ready, we retrieve both of them and compare them in
      code. Here is pseudocode:

      n = size of A
      m = size of B
      i = 0
      j = 0
      setA = [] // List of elements that present only in A
      setB = [] // List of elements that present only in B
      intersection = [] // List of elements that present in A and B
      
      while i < n or j < m {
        if j == m {
          setA.add(A[i])
          i = i + 1
        } else if i == n {
          setB.add(B[j])
          j = j + 1
        } else if A[i] < B[j] {
          setA.add(A[i])
          i = i + 1
        } else if B[j] < A[i] {
          setB.add(B[j])
          j = j + 1
        } else {
          intersection.add(A[i])
          i = i + 1
          j = j + 1
        }
      }
      

      Explanation: We use the fact that A and B are sorted. We have two indexes, both starting at zero. Compare the
      two first elements of A and B. If A[0] is less than B[0], we know
      that A[0] is present only in A so we add it to the list setA and
      increase index of A by one. If B[0] is less than A[0], we add B[0]
      to the list setB and increase index of B by one. If A[0] == B[0] we
      add A[0] to the list of intersections and increment both indexes.
      This code also works in linear time O(N) where N is total number of
      elements in both A and B.

      Note that this approach will work with any database which can return sorted list, meaning you can store it in a traditional SQL database and retrieve lists using ORDER BY twitter_id).

    Have a look at all Data types supported by Redis and full list of their commands, they are nicely documented. Redis also have official clients available in many languages so this shouldn’t be a problem.
    You can still store important data in an SQL database and let Redis handle lists of ids.

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

Sidebar

Related Questions

I have a basic web app that given a url, hits a database, does
I am creating a Twitter app to share photo to Twitpic. i have given
I have to store messages that my web app fetch from Twitter into a
Ok twitter might be great for social media but for a small app that
Assuming that you already have created an oauth client app in twitter, you can
I have an app that creates and stores a session with a given start
I have an app that stores times in GMT, but associated with airports which
I have an app, and the username field will convert any given value to
I have been given an app written by someone else and the error I
Given and coredata based app using an Indexcard metaphor. Each Indexcard can optionally have

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.