title: DynamoDB table design for social network
body: <p>I got a thinking-problem in DynamoDB.
  My structure is looking as following: </p>
  
  <ul>
  <li><p>primary key = "id"</p></li>
  <li><p>sort key = "sort"
  I have posts, users and "user A following user B" relationships.</p></li>
  </ul>
  
  <p><strong>Users:</strong></p>
  
  <ul>
  <li>id=1234</li>
  <li>sort="USER_USER_1234"</li>
  <li>name="max" (for example)</li>
  </ul>
  
  <p>-</p>
  
  <ul>
  <li>id=3245</li>
  <li>sort="USER_USER_3245"</li>
  <li>name="tom"</li>
  </ul>
  
  <p><strong>Post:</strong></p>
  
  <ul>
  <li><p>id=9874</p></li>
  <li><p>sort="POST_POST_1234 (because its created by user id 1234)</p></li>
  <li><p>createdAt=1560371687</p></li>
  </ul>
  
  <p><strong>Following:</strong></p>
  
  <ul>
  <li><p>id=1234</p></li>
  <li><p>sort="USER_FOLLOW_3245" </p></li>
  </ul>
  
  <p>--> tom follows max (but max not tom)</p>
  
  <p>How could I design a query to get all posts by the people which tom(id=3245) is following? So in my case the post id 9874?
  My approach was to put a GSI where sort is the primary key and id is the sort key (that i can query all people which user A is following), than get all the posts from the users (with help of the same GSI) and sort the result after a second index where createdAt is the sort key. The problem is that this needs much much querys (imagine user A would follow 10000 people and they all make posts). Is there a technique or design thinking approach which you could recommend for this situation? My second approach was to index the whole application table to elastic search and do a nested query. Would this make more sense? Or would you recommend using another type of database like AWS neptune?</p>