design-patterns

  • A macro is how you extend a framework class without extending it

    Adding a method to a collection or a response means subclassing, and subclassing a framework class means every place that constructs one has to know about your subclass.…

  • The 5.5 exception that renders itself

    Custom exceptions have always had to be translated into a response somewhere in the handler, which turns one file into a growing chain of instanceof checks. 5.5 lets…

  • A circuit breaker before the third-party outage

    A payment provider was slow and the whole site went down with it. A timeout bounds one request; it does nothing about how many are waiting at once.

  • Mailable classes and why the view is not the email

    An email assembled in a controller — subject here, view there, attachments in a third place — cannot be tested without sending it, and the subject line ends…

  • Designing an API two mobile clients can live with

    Two apps, two release cycles, and neither can be forced to update. What is additive, what is not, and the decisions that have to be made before the…

  • A circuit breaker has three states and people implement two

    Closed and open are obvious: pass through, or fail fast. The third state is what makes it a breaker rather than a switch — half-open lets exactly one…

  • A saga is a workflow with compensation, not a transaction

    A distributed transaction is not available, so the pattern is: do each step, and if a later one fails, run compensating actions to undo the earlier ones. Compensation…

  • An event-driven seam between two services

    The synchronous call between two services was the reason both were down. Publishing an event decouples their availability — and makes eventual consistency a business decision.

  • Laravel 5.5 and the packages that install themselves

    The first release where installing a package is one command. Auto-discovery removes two config edits per package, and hides the fact that they happened.

  • Custom collection classes on a model

    Behaviour that belongs to a set rather than to a single record — the total of a group of order lines, whether any of them is backordered —…