API vs Trigger, which is better for performance?

Hi all,

Does anyone know what the difference in performance is between scheduling a backend API for current time, and having a trigger? Does having a trigger imply any extra work by the server, as it’s constantly ‘watching’ for its cue?

Say I want to trigger an email when a user completes their profile:

API Option

  1. User clicks ‘button complete’
  2. Make change to current user: Profile Complete = Yes
  3. Schedule ‘API Send Welcome email’ to current date and time

Trigger Option

  1. User clicks ‘button complete’
  2. Make change to current user: Profile Complete = Yes
  3. Trigger: User Before Now Profile Complete was not ‘Yes’ and User Now Profile Complete is ‘Yes’. Action: Send Welcome Email.

Practically speaking a trigger is more convenient but I don’t know which will have better performance.

Thanks for any advice in advance

Database triggers are native to Postgres (bubble’s back end) so I suspect they are leveraging that, rather than it constantly watching.

1 Like

This is more of a note to self, but could be useful to you: when using triggers ensure they are super specific so not to unleash an infinite loop.

2 Likes

Thanks for the insight, will go with triggers