title: AWS S3: Recommend Nested Bucket Architecture
body: <p>I am having challenges architecting my S3 bucket structure. </p>
  
  <p>My Application</p>
  
  <p>I have several types (roles) of users and each user has different types of PDF documents that will be uploaded to S3. The user will see each document in their dashboard and should be able to view the PDF from the application (ideally by opening in a new tab instead of downloading it). Below is an example:  </p>
  
  <p>User Roles</p>
  
  <ol>
  <li>role_a</li>
  <li>role_b</li>
  </ol>
  
  <p>User Documents (for role_a)</p>
  
  <ol>
  <li>document_type_a (filename: 0888a5ce)</li>
  <li>document_type_b (filename: c00630fr)</li>
  <li>document_type_c (filename: 2349d1c)</li>
  </ol>
  
  <p>User Documents (for role_b)</p>
  
  <ol>
  <li>document_type_x (filename: fe294090)</li>
  <li>document_type_y (filename: cad2d3dc)</li>
  </ol>
  
  <p>Each user can have zero or more documents.</p>
  
  <p>My questions:</p>
  
  <ol>
  <li>What is the most optimal way to design a nested S3 bucket structure?</li>
  <li>The filename will be saved in the database for each user. In addition to this, what other components of the S3 bucket structure should be saved in the database and what components should be derived from the application to optimize uploading and downloading of these PDF documents?</li>
  <li>In the above nested structure, what would be the bucket name and what would be the key of the document?</li>
  </ol>