Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
How to defer a slow database operation with SQLAlchemy / Python

I've got a REST interface to a database, implemented in Python FastAPI + SQLAlchemy. I want to run some (relatively) costly operations on my data, such as calculating cryptographic hashes or signatures. My hope is to be able to:

  1. Perform the insert, so that all referential integrity is checked by the database.
  2. Return the REST response to the front-end (primary key of insert).
  3. Asynchronously calculate the costly hash/signature/whatever, and update into the DB (same table).

I'd prefer to have a cross-database solution, but it seems running a trigger on insert/update might be the way to go. If so, my target in production is PostgreSQL.

Does anyone have a suggested approach they'd favour?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I would try to separate the concerns.

  • Build a fast REST service that does items 1 and 2 (concern: consistent data persistence);
  • Create a scheduled job that does item 3 in the background using pgAgent or s/th similar (concern: data "decoration") or use a notify/listen setup to invoke a separate process.

Running a trigger would do the actions synchronously. As far as I understand this is not your intention.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!