API Design: PDF generation in a REST-API

We have a REST-API (NextJS) that uses react-pdf for PDF generation and s3 as a storage for these. One Route is handeling the Payment, it has these main task: - Create a XML, for the Bank that we upload manually - Updating the dB (marking stuff as booked, year, month and Invoice name) - Create a CSV, for tax stuff - Create & Upload Invoices (PDFs) the XML and CSV File is getting downloaded as a ZIP and also uploaded to s3 as a backup. The db is getting updated no matter what happens with the PDF generation and upload, like optimistic updates. So the PDFs are not used we are just awaiting the creation and upload, the process logs errors itself, this is also the case for other Routes where PDFs are getting created and uploaded, but on error we only Log, no feedback to the enduser. The PDF generation and upload takes a long time (2-4s). The Payment route is taking very long, exceeding the 5min timeout for serverless and other routes are uneccessary long because of PDF generation. THE QUESTION Is it a good Idea to make a new endpoint that is handeling the PDF generation? I am thinking of something like that: - authentication with a secret in the env (like a cronjob) - For the different types of PDFs we have a unique Query: eq: pdf_gen?type=invoice - we would also have zod validators for each PDF - the File name would be passed in the req body, the key for the file would be created from the recieved data - in the payment route (or other routes this PDF gen) we simply just invoke this enpoint with the secret, the type query param. and the needed data for one PDF Since we are using serverless functions with vercel, we should be able to handle the invocation of the same route ~1000 times in like a second. also s3 can handle this amount of request. 1. is it bad practice to invoice itself in an REST-API? 2. is it bad to pass the Filename as part of the request, but the Key is generated from the given data for the PDF? eg.: is that bad design
1 Reply
Balduin
Balduin13mo ago
(was at 0 chars left, that why end is phrased so short) would appreciate some input on this!
Want results from more Discord servers?
Add your server