Step 17 of 21
·
4 minutes
Credit Score API
The Scenario
The mobile app needs to display credit scores. Credit score calculation
takes 30 seconds — too slow for a synchronous API response.
The client wants to submit a request, poll for the result, and display it when ready.
The Challenge
How do we return results from background jobs to API clients?
The Solution
Use
Job Results to store and retrieve job outputs:
// The job returns a result
public CreditScore calculateCreditScore(String customerId) {
// Complex calculation...
return new CreditScore(750, "Excellent");
}
// API endpoint to get the result
public CreditScore getCreditScore(UUID jobId) {
JobResultWithBackOffInfo result = jobScheduler.getJobResult(jobId);
if (result.isAvailable()) {
return result.getResult();
}
throw new RetryAfterException(result.backoffPeriod());
}
JobRunr serializes the result and stores it in the database,
preventing (D)DOS from polling clients!
Read the documentation →
Try It Yourself
Request a credit score calculation via the API. Poll for the result
and watch it appear once the background job completes.
You need to log in to perform write operations. You can still view the code solution and dashboard.