nitin
nitin

Reputation: 88

Optimising feedback forms backend design for gaming applications

I have to design and develop a feature in the backend for feedback forms in a gaming application.

So the use case is that admin will create multiple feedback forms which will be shown to the user in the gaming application. This form will consist of some questions related to feedback for the application.

The form will have a start time and end time and will only be displayed to user when a form is active i.e. its current time is between the start time and end time and when a certain set of triggers are obtained for a user. Here trigger could be game won or XP Increased. These are predefined triggers that will be associated with each form created by the admin.

At the end of the game, an API will be called which will check triggers registered with a user and will fetch relevant feedback from the database according to the triggers registered and the current time. My design was to store this data in some document database (NOSQL) as there is no need for transactions and the format of forms can vary For forms, I would create a collection form_collection with a document structure as below

{
  
  _id: ObjectId,                 // Unique identifier for the form
  title: String,                  // Title or name of the feedback form
  description: String,            // Description or additional information about the form
  created_at: Date,               // Timestamp indicating when the form was created
  status : bool, 
  start_time : Date, //Timestamp when the form will be active
  end_time : Date, //Timestamp when the form will be inactive
  questions: [
    {
      question_id: ObjectId,      // Unique identifier for the question
      question_text: String,       // The actual text of the question
      question_type: String,       // Type of question (e.g., open-ended, multiple-choice, rating-based)
      options: [String]            // If applicable, an array of available options for multiple-choice questions
    },
    // Other questions...
  ],
  triggers: [ObjectId]            // Array of trigger IDs associated with the form 
}

And the user collection will have document structure as

{
  _id: ObjectId,                 // Unique identifier for the user
  username: String,               // User's username or identifier
  email: String,                  // User's email address
  // Other user profile fields...

  triggers: [
    {
      trigger_id: ObjectId,       // Unique identifier for the trigger
      triggered_at: Date          // Timestamp indicating when the trigger was triggered for the user
    },
    // Other triggers...
  ]
}

Now there will be two flows

Flow one: Storing trigger info with the user

Whenever a trigger happens Game won that trigger will be stored inside user collection

Flow two: Fetching feedback form for a user

We will fetch a current set of triggers for a user and then query document collection where the current time is between the start_time and end_time of forms and then from that list we will filter those documents which have all the triggers mapped that were obtained by the user This will involve searching two times and does not seem optimized. I can add indexes over start time and triggers array in form_collection however this does not seems optimized for high traffic.

Another approach I can think of is

Precompute trigger list

Whenever the admin creates a form we will have a key in some Key-value kind of nosql database for a set of triggers and a list of documents will be added there. This will shift some complexity to form creation from admin.

<TriggerOne-TriggerTwo-TriggerThree> : [Forms]

Is there any other approach that could reduce the complexity of fetching forms each time and also is the pre-computation approach correct as it will hit a limit for the list of forms (no of forms that can be added in a list) Any suggestion would be highly appreciated. Also, I am a fresher so sorry if I was not able to explain correctly/sufficiently, and is open to discussion in comments for any rectification of requirements. I can use any database for backend. MongoDB is not neccesary. Thank you again, guys.

Upvotes: 1

Views: 63

Answers (0)

Related Questions