ololo
ololo

Reputation: 2076

Parse Server Cloud Code execution in multiple instances

I plan to deploy Parse Server in a Kubernetes cluster with a Horizontal Pod Autoscaler (HPA), which can scale Parse Server to a maximum of 3 instances based on demand.

I have the following Cloud Code implemented, and I need clarification on its behavior when multiple Parse Server instances are running due to scaling:

module.exports = {
  initialize: () => {
    Parse.Cloud.beforeSave('Post', (request) => {
      const post = request.object;

      if (!post.get('title')) {
        throw new Error('Post must have a title.');
      }

      post.set('updatedAt', new Date());
    });

    Parse.Cloud.afterSave('Post', async (request) => {
      const post = request.object;
      console.log(`Post saved: ${post.get('title')}`);
    });

    Parse.Cloud.beforeDelete('Post', async (request) => {
      const post = request.object;
      // Send a one-time notification
    });
  }
};

Question:

When a Cloud Code trigger such as beforeSave, afterSave, or beforeDelete is executed, will it:

  1. Be triggered on all instances (i.e., all 3 running Parse Server pods)? Or will it be triggered on only one instance?
  2. Additionally, how can I ensure that an action like sending a notification (in beforeDelete) happens only once, regardless of the number of running instances?

Upvotes: 1

Views: 22

Answers (0)

Related Questions