Software DevelopmentBeginner 1 to 2 hours

Fix an N+1 Query Problem

Optimize a hidden loop that is crushing your database.

The Scenario

An API endpoint `GET /articles` fetches the latest 50 articles. For each article, the ORM runs a separate query to fetch the author's name. This results in 51 database queries for a single API request.

The Brief

Identify the N+1 query in the provided code snippet. Rewrite the database logic to use a SQL `JOIN` or your ORM's "eager loading" feature so that it only takes a maximum of 2 queries to fetch all the data.

Deliverables

  • The optimized code snippet
  • An explanation of why the N+1 problem causes severe performance degradation as traffic scales

Submission Guidance

If using Prisma, look into `include`. If using TypeORM, look into `relations`. If using raw SQL, write a `LEFT JOIN`.

Submit Your Work

Your submission is graded against the rubric on the right. If you pass, you get a public Badge URL you can share on LinkedIn. There is no draft save, so work offline first and paste your finished response here.

This appears on your public Badge.

We'll email you the permanent link to your Badge so you never lose it. Not shown publicly.

0/20000 charactersMarkdown supported

One per line or comma separated. Up to 5 links.

Loading security check...

By submitting, you agree your submission text, name, and evaluation will appear on a public Badge URL.