Describe a scenario where you had to optimize a slow database query or a bottlenecked API endpoint for a client.