chapter five

5 Build performance into your architecture

 

This chapter covers

  • Distinguishing speed, scalability, and resilience as separate architectural concerns
  • Choosing rendering and initialization patterns for web, mobile, and desktop
  • Selecting backend architectures: services, APIs, edge computing, and databases
  • Designing database layers for performance at scale
  • Using message queues for background processing
  • Improving inherited architectures without risky rewrites

No amount of code-level optimization can overcome an underlying architecture that is inherently slow. On a recent web project, we spent three months optimizing JavaScript bundle sizes, code splitting strategies, and rendering performance, yet users still waited 4-5s before seeing content. The problem was not the frontend at all; the underlying architecture required seven sequential API calls to different backend services before the page could render anything. Pricing, inventory, promotions, customer preferences, financing options, stock locations, product configurations: each came from a separate legacy system, each adding up to 400ms of latency.

If your initial page load requires seven sequential round trips to different services, clever JavaScript optimization will not make it fast. If your mobile app initializes a dozen SDKs on startup, threading will not fix the fundamental problem. The architecture you choose sets the performance ceiling for your application.

5.1 Speed, scalability, and resilience

5.2 Rendering and initialization strategies

5.2.1 Web rendering patterns

5.2.2 Mobile initialization patterns

5.2.3 Desktop initialization patterns

5.3 Backend architecture

5.3.1 Monoliths, microservices, and serverless

5.3.2 Edge computing and CDN architecture

5.3.3 API design: REST, GraphQL, and gRPC

5.3.4 The Backend for Frontend pattern

5.3.5 Message queues and event-driven patterns

5.4 Database architecture choices

5.4.1 Relational vs NoSQL

5.4.2 Read replicas and replication lag

5.4.3 Connection pooling

5.4.4 Indexing strategy

5.5 Improving existing architecture

5.5.1 Incremental migration patterns

5.5.2 Set targets and know when to stop

5.6 Summary