System requirements


Functional:

List functional requirements for the system (Ask the chat bot for hints if stuck.)...


  • Users can store text (10000 characters) to website
  • Users can set a time for text to expire
  • Users can edit/delete text
  • Users should be able to see all their texts on a dashboard before it expires


Non-Functional:

List non-functional requirements for the system...


  • Scalable
    • Many users over a number of countries should not break system
  • Consistent
    • Users should be able see their most up to date
    • No matter when or where they are (different countries)
  • Available
    • Users should be able to access their texts in a fast manner
  • Authentication
    • Users should only be able to see their own texts



Capacity estimation

Estimate the scale of the system you are going to design...


Assume 10000 DAU:

  • A user stores 10 texts per day
  • 10*10000 = 100,000 stored texts a day
  • System should be able to handle 200,000 stored texts a day

Data Estimation:

  • If character limit is 10000, with ASCII, maximum size would by 10000 bytes; 10KB
  • 10*200,000 = 2,000,000KB = 2GB per day
  • 2*365 = 730GB per year


API design

Define what APIs are expected from the system...


/v1/user/auth => authenticates user

{

user_id,

credentials

}


POST /v1/user/text/add => adds texts from database

{

user_id,

text,

expiration_time

}


PUT /v1/user/text/{text_id}/ => edits texts from database

{

user_id,

text_id

new_text?,

expiration_time?

}


DELETE /v1/user/text/{text_id}/ => deletes text from database

{

user_id,

text_id

}


/v1/user/saved_texts => returns texts saved by the user

{

user_id

}



Database design

Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...


User_Mapping{

user_id,

email

}


Text_Mapping{

user_id,

text_id,

text,

expiration_date,

created_at,

}



High-level design

You should identify enough components that are needed to solve the actual problem from end to end. Also remember to draw a block diagram using the diagramming tool to augment your design. If you are unfamiliar with the tool, you can simply describe your design to the chat bot and ask it to generate a starter diagram for you to modify...


  • rate limiter
  • api gateway
  • user service
    • authentication
  • text service
    • accesses database for texts add/edit/delete requests
  • database
    • postgresDB for horizontal scaling
  • cache for frequently used texts




Request flows

Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...


add/edit/delete text request:

  • Client sends add/store/delete requests to API Gateway
  • API Gateway will send requests to Text Service
  • Text service will check in cache for frequently used texts
  • If not in cache, access database


saved texts request:

  • Client sends saved texts request to API Gateway
  • API Gateway will send requests to Text Service
  • Text service will check in cache for frequently used texts
  • If not in cache, access database
  • Text service returns saved texts to client





Detailed component design

Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...


Text Service:

  • will hand the add/edit/delete of texts
  • return saved texts to user

Rate limiter:

  • will prevent users from spamming requests



Trade offs/Tech choices

Explain any trade offs you have made and why you made certain tech choices...


PostgreSQL reasons:

  • The need for complex queries for tracking progress.
  • Ensuring data integrity through foreign key constraints.

Redis for cache reasons:

  • faster data access


Failure scenarios/bottlenecks

Try to discuss as many failure scenarios/bottlenecks as possible.


  • Limit the amount of requests to prevent malicious actors
  • Prevent users from malicious texts



Future improvements

What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?


  • Add text sharing between users
  • longer number of characters