Code Room
Code reviewHardcr-g349
Subject Pagination bugsLevel Senior–Staff~25 minCommon in Networking & APIs · Concurrency interviewsIndustries Software development, Technology

Question

Review this Python offset-pagination endpoint for an activity feed that receives frequent inserts at the top.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix — specific and kind.

Talk through your review
Code to reviewpython
@app.get('/api/feed')def feed():    page = int(request.args.get('page', 1))    size = 20    offset = (page - 1) * size    items = db.execute(        'SELECT id, body, created_at FROM activity '        'ORDER BY created_at DESC LIMIT %s OFFSET %s',        (size, offset),    ).fetchall()    return jsonify({'page': page, 'items': [dict(i) for i in items]})
Run or narrate your approach, then ask the coach.