An API that works for ten users and an API that works for ten thousand are usually the same code with different habits around it. These are the habits I reach for on every Laravel API I ship, roughly in the order they start to matter.

Version it and shape the output with API Resources

Never return Eloquent models straight from a controller. The day you rename a column, every client breaks. API Resources put one stable layer between your database and your JSON, and a version prefix gives you room to change it later.

// routes/api.php
Route::prefix('v1')->group(function () {
    Route::apiResource('orders', OrderController::class)->middleware('auth:sanctum');
});

// app/Http/Resources/OrderResource.php
public function toArray(Request $request): array
{
    return [
        'id'     => $this->id,
        'status' => $this->status,
        'total'  => $this->total,
        'items'  => OrderItemResource::collection($this->whenLoaded('items')),
        'placed_at' => $this->created_at->toIso8601String(),
    ];
}

whenLoaded matters: the resource never triggers a hidden query, so the controller decides exactly what gets loaded.

Validate in Form Requests, not controllers

A Form Request keeps validation and authorization out of the controller, makes them testable on their own, and returns a consistent 422 JSON body for free.

class StoreOrderRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can('create', Order::class);
    }

    public function rules(): array
    {
        return [
            'items'            => ['required', 'array', 'min:1'],
            'items.*.sku'      => ['required', 'exists:products,sku'],
            'items.*.quantity' => ['required', 'integer', 'between:1,50'],
        ];
    }
}

Authenticate with Sanctum

For first-party apps and mobile clients, Sanctum's personal access tokens are enough and far simpler than a full OAuth server. Give each token the narrowest abilities it needs and check them where it counts.

$token = $user->createToken('mobile', ['orders:read', 'orders:write'])->plainTextToken;

// in a controller or policy
abort_unless($request->user()->tokenCan('orders:write'), 403);

Rate limit per user, not just per IP

Define named limiters so you can tune them without touching routes. Authenticated users get a limit keyed by user id (so one office behind a single IP is not punished), and anonymous traffic falls back to the IP.

// app/Providers/AppServiceProvider.php
RateLimiter::for('api', function (Request $request) {
    return $request->user()
        ? Limit::perMinute(120)->by($request->user()->id)
        : Limit::perMinute(30)->by($request->ip());
});

Kill N+1 queries before they reach production

The most common reason an API slows down is a loop that quietly runs one query per row. Eager load what the response needs, and make Laravel complain in development whenever something is lazy loaded by accident.

// AppServiceProvider::boot()
Model::preventLazyLoading(! app()->isProduction());

// controller
$orders = Order::query()
    ->with(['items.product', 'customer:id,name'])
    ->latest()
    ->cursorPaginate(25);

Prefer cursorPaginate for large, fast-growing tables: it avoids the expensive OFFSET scans that make deep pages slow.

Cache what is expensive and rarely changes

Cache the result of slow, read-heavy queries with a sensible expiry, and use Cache::remember so there is exactly one place that builds the value. Use tags or explicit keys so you can invalidate when the underlying data changes.

$stats = Cache::remember('dashboard:stats', now()->addMinutes(10), function () {
    return Order::query()
        ->selectRaw('count(*) as orders, sum(total) as revenue')
        ->whereDate('created_at', today())
        ->first();
});

Move slow work to queues

If a request sends an email, generates a PDF or calls a third-party API, the client is waiting for something it does not need to wait for. Dispatch a job, return 202 Accepted and let a worker finish it. Make jobs idempotent so a retry never charges or emails twice.

public function store(StoreOrderRequest $request)
{
    $order = Order::create([...]);

    SendOrderConfirmation::dispatch($order)->afterCommit();

    return (new OrderResource($order))->response()->setStatusCode(201);
}

Return errors in one predictable shape

Clients should be able to handle every failure the same way. Render exceptions for API routes as JSON with a stable structure, and never leak stack traces or SQL in production.

// bootstrap/app.php
->withExceptions(function (Exceptions $exceptions) {
    $exceptions->render(function (ModelNotFoundException $e, Request $request) {
        if ($request->expectsJson()) {
            return response()->json(['message' => 'Resource not found.'], 404);
        }
    });
})

Measure before you optimise

Everything above is cheap to do up front. Anything beyond it, such as read replicas, Redis for sessions and queues, or splitting services, should be driven by numbers: slow query logs, response time percentiles and queue depth. Add the habit of looking at those numbers and the architecture decisions mostly make themselves.