<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="356092" data-post-id="356092">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jaybe78" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jaybe78/120/36069_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jaybe78
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I agree with you, you don’t want to fetch 1000 friends of a user if only one in there is “online”.</p>
<p>But what do you mean by “online” ?<br>
“Online” in the context of a graph or SQL DB might be very different than in the context of a Phoenix app.</p>
<p>I don’t think we can say a user is online with certainty because there’s been an update a few minutes ago, of a column “last_active” in a table, whose purpose is to approximately say, that a user was “recently” active…</p>
<p>But ok, let’s say each client periodically update a column like “last_active” with current datetime, so that the fetching friends query can filter out the ones that have been inactive for more than x minutes.</p>
<p>It’s true that with DynamoDB you cannot make join so there’s no way to gets friends of users and filter with “last_active” date, because that column would only be updated at the user level and not for each friends relationship.</p>
<p>Though my assumption is that since DynamoDB is way faster than SQL, it would not be a problem to fetch more users, especially because they would only be fetched once, and then cached.</p>
<p>The other things to consider in my mind are:</p>
<ol>
<li>Filtering users from “last_active” could be a waste of time. In the sense, that this column could be way further than the “truth” than we think. What do I want to know ? Whether an user is available or not right.</li>
</ol>
<p>In the application I develop, people can quickly go from “available/online” to “busy” status and so with that “last_active” date, that we rely on initially, there will always be a delay.</p>
<p>It will never be as fast/accurate as Presence or Tracker so you could also say, “What’s the point of querying with a join in a SQL DB knowing the data it returns, might be obsolete when it arrives ?”</p>
<ol start="2">
<li>You could have only 1 friend online at a T moment and 90% of your friends  online at T+1, so you would end up, querying that user’s friends multiple times anyway, while you could have fetched the whole thing the first time and cache it.</li>
</ol>
<p>In the end, what is returned by queries at some time could be far from the “truth”</p>
<p>My current architecture currently makes use of DynamoDb and streams some data to PostgresSQL.</p>
<p>I have considered using Postgres and fetch friends using that “last_active” date, but then, I thought, may be PostgreSQL would not be able to handle the load as good as DynamoDb.</p>
<blockquote>
<p>You will need to adapt the application to make good use of the relational model, but once you have, a sustained “50000 users with 1000 friends each leaving and joining every second” – and likely many of your other problems too – become a non-issue.</p>
</blockquote>
<p>the leaving and joining of users every second would not be an issue at the app level I guess, because once they are fetched and cached, you can quickly go through them and check their status.<br>
I’m currently tracking my users’s status in an ETS table.<br>
I don’t think it would be a big issue to go through 1000 users in an ETS table to filter those that are away/busy<br>
It would be actually way more complicated for a graph or SQL DB though… even with users periodically updating their status.</p>
<p>That’s tricky decision so that’s why I was asking.</p>
<p>Thanks</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356092" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/fetch-online-userss-friends-for-large-quantity-of-users/69343/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-356092" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356092"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="356113" data-post-id="356113">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jhogberg" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/120/24176_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jhogberg
                  </h3>
		          </div>
						
			          <div class="user-title">
									<span>Erlang Core Team</span>
			          </div>
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="jaybe78" data-post="12" data-topic="69343">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jaybe78/48/36069_2.png" class="avatar"> jaybe78:</div>
<blockquote>
<p>It would be actually way more complicated for a graph or SQL DB though… even with users periodically updating their status.</p>
</blockquote>
</aside>
<p>Not when you know how to leverage the database. I’ve been in this situation before <sup class="footnote-ref"><a href="#footnote-356113-1" id="footnote-ref-356113-1" rel="nofollow">[1]</a></sup> and tried to dissuade you, but you seem to have made up your mind already. Good luck <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<hr class="footnotes-sep">

<ol class="footnotes-list">
<li id="footnote-356113-1" class="footnote-item"><p>Swap DynamoDB for MongoDB, but better database throughput wouldn’t have helped. <a href="#footnote-ref-356113-1" class="footnote-backref" rel="nofollow">↩︎</a></p>
</li>
</ol> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356113" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/fetch-online-userss-friends-for-large-quantity-of-users/69343/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-356113" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356113"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="356125" data-post-id="356125">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jaybe78" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jaybe78/120/36069_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jaybe78
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>LOL ! not really no… Otherwise why would I be here asking !? <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>The other thing you don’t mention is that if I go for SQL solution I’m gonna have to handle config and administration of a SQL DB while I’m already busy on other stuff.</p>
<p>DynamoDB offers me some “free” time… but may be more expensive ^^</p>
<p>Anyway as I said, tricky decision</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356125" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/fetch-online-userss-friends-for-large-quantity-of-users/69343/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-356125" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356125"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="356142" data-post-id="356142">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="garrison" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  garrison
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="jaybe78" data-post="12" data-topic="69343">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jaybe78/48/36069_2.png" class="avatar"> jaybe78:</div>
<blockquote>
<p>I agree with you, you don’t want to fetch 1000 friends of a user if only one in there is “online”.</p>
</blockquote>
</aside>
<p>You have two predicates.</p>
<ul>
<li><code>user</code> has a <code>friend</code> relationship with <code>current_user</code></li>
<li><code>user</code> has <code>status=online</code></li>
</ul>
<p>Assuming you have two indexes, for each of these predicates, you have two choices:</p>
<ul>
<li>scan user’s friends and then filter for <code>status=online</code></li>
<li>scan all <code>online</code> users and then filter for friendship</li>
</ul>
<p>If you use a relational database it will pick one for you - almost certainly the first, because the set of friends is going to be a lot smaller than the set of all online users.</p>
<p>Of course, there is a third option: you could create an index of all online friends, essentially materializing the predicates.</p>
<p>But the crux of the issue here is: you seem to be storing the <code>online</code> status in ephemeral <code>:ets</code> tables instead of in the database (not necessarily a bad idea). So you are responsible for performing the filtering yourself. Meaning you are back to the same choices:</p>
<ul>
<li>scan all <code>online</code> users from the ets table and then filter for friends</li>
<li>scan all <code>friends</code> from the database and then filter for online</li>
</ul>
<p>The third option (indexing on both fields) is no longer available to you because you have no way to atomically update both the database and your ets table, so you risk corrupting the state. Of course maybe this is not a big deal since your <code>online</code> state is so ephemeral anyway.</p>
<aside class="quote no-group" data-username="jaybe78" data-post="1" data-topic="69343">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jaybe78/48/36069_2.png" class="avatar"> jaybe78:</div>
<blockquote>
<p>My initial idea is to fetch users’s friends and filter them with what is stored in the ETS table mentioned just before, to know whether one user is online or not.</p>
</blockquote>
</aside>
<p>I think you had the right idea from the beginning here - this is what you should do IMO. Also consider the following: it is common for a “friends list UI” to show both online <em>and</em> offline friends. I would go so far as to say this is the default. So you’re probably not losing much querying the whole friends list anyway - you may as well just display it!</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356142" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/fetch-online-userss-friends-for-large-quantity-of-users/69343/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-356142" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356142"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="356143" data-post-id="356143">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="garrison" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  garrison
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote group-Erlang-Core-Team" data-username="jhogberg" data-post="8" data-topic="69343">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jhogberg/48/24176_2.png" class="avatar"> jhogberg:</div>
<blockquote>
<p>The moment that you start doing relational operations over data that you have retrieved from a NoSQL database, you have invented your own half-finished, slow, and bug-ridden relational database.</p>
</blockquote>
</aside>
<p>I fully agree with this BTW, my answer above should be interpreted as “if you’re going to do it that way”. The join inside the database is likely to be faster because it won’t send all of the friends over the wire (that is unless you want to load the full friends list anyway).</p>
<p>And just because the database is probably better-optimized than your application code (ets is pretty fast though).</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356143" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/fetch-online-userss-friends-for-large-quantity-of-users/69343/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-356143" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356143"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="356182" data-post-id="356182">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="boxxxie" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/boxxxie/120/5671_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  boxxxie
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>30k users is a very small amount of data. you actually can do something like use an in memory graph, or embeded graph db. when you start your app read in the whole DB and then do all your work via the graph and keep it in sync with the DB on writes. you can seed your DB and benchmark the effect of solving the problem in this way. if you are able to do things in memory on your app server you eliminate a lot of complexity.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356182" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/fetch-online-userss-friends-for-large-quantity-of-users/69343/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-356182" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356182"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #16"></div>
  </section>
</div>
    <div class="postbit" id="356192" data-post-id="356192">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jaybe78" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jaybe78/120/36069_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jaybe78
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks for your answer Mr Garrison.</p>
<p>yes I thought about displaying all  the users and page the result but for what I want to do, it’s not really ideal.<br>
I don’t want a user to scroll through a hundreds of his friends in search of someone online to play with.<br>
That would be a waste of time… especially for someone with 1000 or more friends whose only friend online is at the very bottom of the list <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>Regarding scanning table, it’s really not an option for me, would be a waste of time, performance and money…</p>
<p>Let’s say I go for the SQL option:</p>
<p>So basically I’d have 2 tables Users(user_id, last_active_date, status) and Friends(user_id, friend_id)</p>
<p>On the Users table I can create a composite index on “last_active_date” and “status” (away, offline, online)</p>
<p>last_active_date will be updated in batch at the app level to optimize server round trip.</p>
<p>Regarding the Friends table I would store only one side of the relationship</p>
<p>To fetch the online friends of a user joining I could do something like:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">select user_id, friend_id from Friends f
inner joins Users u on (f.user_id = u.user_id or f.friend_id=u.user_id)
where u.user_id = :user_id
limit 100
</code></pre>
<p>or may be I could even do that in batch rather for a single user</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">where u.user_id in (:user_ids)
</code></pre>
<p>Is there anything else I can look at to improve performance, bearing in mind, that table will be massive at some point ? Partitioning ? Materialized views ?</p>
<p>I heard Materialized views do not scale very well, and about partitioning the Friends table ? would that really benefit in anything ?</p>
<p>At the app level to improve even more performance, once the first users joining start fetching their friends I can store in memory their relationship for each of them:</p>
<p>Basically if users 1 ans 2 join and both have friendship with user 3, when user 3 joins, I can first check the ets tables where already fetched relationships are stored, rather than directly querying the DB.<br>
The idea is to constantly take advantage of the relationship already fetched by other users, so that I can display result faster and have a kind of an in memory “online” representation of users friendship.</p>
<p>the other thing is would broadway/genstage benefits in that scenario to not overload the SQL DB?</p>
<p>Is that too naïve kind of approach ?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356192" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/fetch-online-userss-friends-for-large-quantity-of-users/69343/18">Post #17</a>
	                </div>
	            </div>
              <div id="likers-container-356192" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356192"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #17"></div>
  </section>
</div>
    <div class="postbit" id="356194" data-post-id="356194">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jaybe78" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jaybe78/120/36069_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jaybe78
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>30k users multiplied by up to 1000 friends for each user.<br>
Yes not that much for now but will get bigger so looking for some optimised solution.</p>
<p>I have not found in Elixir any in memory graph DB, that’s why I though about storing relationship in multiple ets tables across a cluster of nodes.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356194" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/fetch-online-userss-friends-for-large-quantity-of-users/69343/19">Post #18</a>
	                </div>
	            </div>
              <div id="likers-container-356194" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356194"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #18"></div>
  </section>
</div>
    <div class="postbit" id="356199" data-post-id="356199">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="boxxxie" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/boxxxie/120/5671_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  boxxxie
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>sorry, i am unsure of the scope of the problem. do you have data and usage patterns, expected active users per second? you could run a graphDB on your server, i think it’s probably overkill. if you think that your data is going to be too much for ram (i suspect very unlikely) then you can do everything in the DB by making a table per friends list. this could be a partition on a relationship table, or this could be something like a materialized view that gets rebuilt on write/friend-added (they are small tables). i think another thing you can do is predict the likelyhood that someone will appear online, and then you can remove those nodes from your graph. how often is someone going to need to know about the 1000 friends statuses? for example you can have a table that records the last time someone logged on/off the site, then use a window of that data to determine what are your high priority nodes. that subset of your total nodes will likely always be small. instead of 30k users and 1000k friends each, you have 1k likely active users with 10 likely active friends. even if you aren’t doing predictions you only need active users in your graph + friend nodes, unless i misunderstand the problem.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356199" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/fetch-online-userss-friends-for-large-quantity-of-users/69343/20">Post #19</a>
	                </div>
	            </div>
              <div id="likers-container-356199" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356199"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #19"></div>
  </section>
</div>
    <div class="postbit" id="356201" data-post-id="356201">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="boxxxie" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/boxxxie/120/5671_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  boxxxie
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="jaybe78" data-post="1" data-topic="69343">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jaybe78/48/36069_2.png" class="avatar"> jaybe78:</div>
<blockquote>
<p>I could have 30_000 or more users joining the app at the same time</p>
</blockquote>
</aside>
<p>i think this may be a bigger problem than the data storage. this many people signing up at the same time can put a lot of strain on a server and 3rd party APIs you may be using.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="356201" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/fetch-online-userss-friends-for-large-quantity-of-users/69343/21">Post #20</a>
	                </div>
	            </div>
              <div id="likers-container-356201" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="356201"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #20"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <a class="load-more-button" data-turbo-stream="true" href="/topics/69343/load_more?page=3">Load more posts (6 remaining)</a>
</div></template></turbo-stream>