Debian Codegraph @

www/src/content/essays/does-hypermedia-scale.md

raw symbols SCIP
1 ---
2 title: "Does Hypermedia Scale?"
3 description: "In this essay, Carson Gross examines whether Hypermedia-Driven Applications (HDAs) can effectively scale across different dimensions of software development, including system nodes, application performance, feature count, feature complexity, and team size. The analysis explores both the strengths and limitations of hypermedia in each context, ultimately demonstrating that HDAs can scale well in most scenarios while acknowledging specific challenges with complex client-side features."
4 created: 2023-11-06
5 modified: 2023-11-06
6 authors: ["Carson Gross"]
7 tags: ["the-case-for-hypermedia"]
8 ---
9
10 One objection that we sometimes hear to htmx and hypermedia is some variation of the following:
11
12 > Well, it might work well for something small, but it won't scale.
13
14 It is always dangerous to provoke us with essay-fodder and so lets dig into this claim a bit and see if we can
15 shed some light on whether [Hypermedia-Driven Applications](/essays/hypermedia-driven-applications) (HDAs) can scale.
16
17 ## Scaling
18
19 First of all, let's define the term "scaling" and then the contexts that word can be used in development. In a software
20 context, scaling typically means the ability of the software to handle "larger" things. Those things can be:
21
22 * More nodes in a general [system](https://hypermedia.systems)
23 * More user requests (scaling your individual application's performance)
24 * More features (scaling your codebase)
25 * More _complex_ features
26 * More developers (scaling your team size)
27
28 Each of these sense of the word "scaling" demand their own analysis with respect to HDAs.
29
30 ## Scaling Nodes In General
31
32 Although this isn't of much interest to individual developers making decisions about their own applications, it is worth
33 stating that The Web has scaled _incredibly well_ as a distributed networking system. It is the most successful
34 distributed system that I am aware of, in any event.
35
36 This is not necessarily of interest to an _individual_ application developer, but it sets the proper tone: hypermedia
37 can scale.
38
39 ## Scaling Application Performance
40
41 Does hypermedia scale well with _performance_? To answer this question, lets first look at some of the characteristics
42 of performance-scalable software. While there is no authoritative source for these characteristics, most engineers
43 with experience scaling software will agree that most of the items on this list are at least helpful:
44
45 * Software should be _stateless_
46 * Software should support _horizontal scaling_
47 * Features in the software should be _independent_
48 * The performance of the system should be _observable_
49 * The software should utilize caching
50
51 It turns out, happily, that properly designed hypermedia systems can have all these characteristics.
52
53 Statelessness
54 is [a constraint of the REST-ful architecture](https://ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_1_3)
55 that Roy Fielding created to describe the web. In practice, many hypermedia-driven applications use a _session cookie_
56 to manage a small amount of state on the server side, but this is a well-understood technique that hasn't proven fatal
57 in scaling applications.
58
59 Horizontal scaling has a long history in hypermedia-driven applications and dovetails with the stateless nature of most
60 hypermedia-driven applications: early PAAS vendors like [heroku](https://www.heroku.com/) (of blessed memory) offered
61 easy horizontal scaling of rails-driven applications, for example.
62
63 Feature independence is another strength of HDAs. In HDAs, end-points for screens tend to be
64 [_decoupled_](/essays/two-approaches-to-decoupling) from one another in a way that general JSON APIs are not. This
65 means that those endpoints can be monitored, evolved and be tuned independently of one another. We have a long history
66 of
67 tuning these sorts of endpoints to create sub-100 millisecond response times (e.g. minimizing database queries for a
68 given end-point by SQL tuning.)
69
70 Building on the independence of end-points to support various views, platform performance is easy to monitor and
71 understand. Rather than a generalized JSON API that can be accessed in multiple ways across your application, you have
72 UI specific end-points that construct hypermedia for specific views. Determining what is causing a performance issue
73 becomes much easier when views are constructed on the server-side and requests are driven through simple hypermedia
74 exchanges.
75
76 Finally, web applications have a long and storied history
77 of [caching](https://ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm#sec_5_1_4).
78 HTTP offers caching at the browser, controlled by headers. Mature server side frameworks like Rails offer sophisticated
79 caching at the controller layer. Caching is second nature for HDAs.
80
81 All of these combine to make HDAs extremely scalable from a performance perspective. Battle-tested performance
82 techniques
83 are available for scaling your HDA as user load increases.
84
85 Does the HDA approach push more computation onto the server side? To an extent, this is true. However, the difference
86 between the JSON representation for a given resource and the HTML representation for it is not nearly as large as some
87 people think, particularly if you don't include the header and footer information in HTML requests, as is common in
88 htmx-based applications. Network latency and datastore-access typically dominates request time anyway, and the ability
89 to use SQL (or a similar server-side query language) gives you an opportunity to optimize that aspect of the request.
90
91 HDAs also typically have the optimal ["one request per view"](https://twitter.com/htmx_org/status/1721750496086798378)
92 naturally since, well, in HDAs the requests *are* your views.
93
94 ## Scaling With # Of Features
95
96 Because HDAs tend to have independent end-points driven by UI needs, rather than a general JSON data API, scaling with
97 the number of features is typically very easy. Assuming a reasonable Model-View-Controller split on the server side,
98 Controllers and Models tend to be very independent of one another. When features truly overlap, having the features
99 developed and tested on the server-side provides a more controlled and testable environment.
100
101 Views can achieve reuse via server-side includes, found in nearly all server-side templating libraries, or be maintained
102 separately in order to avoid interdependencies.
103
104 All of this is to say that, with reasonable application architecture, HDAs often scale _very well_ with the # of
105 features in an application, especially when those features are inherently decoupled from one another.
106
107 ## Scaling With Complexity Of Features
108
109 Scaling with the # of features is at some level akin to _horizontal scaling_: so long as they are relatively independent
110 they will scale fine (and if they aren't, HDAs will still often scale as well as or better than other options.)
111
112 But what about _deep_ features: features that are complex _in themselves_?
113
114 Here we must split the deep features into two categories:
115
116 * Server-side deep features
117 * Client-side deep features
118
119 For deep server-side features, HDAs are often a great choice. A good example of this is something like an AI chat-bot:
120 this is a very sophisticated server-side feature, but it interacts with the user via a simple textual interface. Many
121 [AI chat-bots](https://www.sliceofexperiments.com/p/building-a-personalized-ask-me-anything) have been built using
122 htmx, with people remarking on how simple it is.
123
124 For deep _client-side_ features, HDAs are sometimes _not_ a great choice. We outline details on this in our essay on
125 [when to choose hypermedia](/essays/when-to-use-hypermedia). To summarize that article: if your UI requires responding
126 to a large number of events
127 quickly (e.g. dragging a map-view) or has significant inter-UI dependencies that cannot be updated in a bulk hypermedia
128 exchange (e.g. a spreadsheet application), the hypermedia approach isn't going to work well
129
130 However, we would note two things:
131
132 * It is often possible to _wrap_ more complex front-end behavior within an HDA application, integrating via events.
133 * Sometimes it is better to [say "No"](https://grugbrain.dev/#grug-on-saying-no) to complex front-end features, or at
134 least consider if a simpler implementation is acceptable that doesn't entail the additional complexity typically
135 found with complex front end frameworks.
136
137 ## Scaling The Team
138
139 The final sense of scaling we will consider is the idea of scaling a development team. Here we must rely on more
140 subjective and anecdotal measures, unfortunately.
141
142 It is our experience (and the experience of others) that HDAs seem to allow you to accomplish more with _fewer_
143 developers.
144 They also eliminate the front-end/back-end split, and the communication friction of this split,
145 since developers become responsible for entire features. Some people _like_ the front-end/back-end split and feel
146 this allows teams to scale better by making the teams independent.
147
148 We do not agree. We think that the front-end and back-end of most web applications are _inherently coupled_ and,
149 therefore,
150 the best approach is to adopt an architecture that accepts this coupling and is designed to handle change well, which
151 the hypermedia approach is (via the uniform interface.)
152
153 Can HDAs scale to teams of 100 or more? This we can't answer because we haven't seen this scenario. But it can certainly
154 scale into the 10s. We can _imagine_ the approach scaling much higher (it did during the web 1.0 era, after all) but
155 at this point we are speculating.
156
157 We prefer smaller teams anyway. 10 developers should be enough for any application.
158
159 ## Conclusion
160
161 So, taking these all together, we have the following conclusion regarding scaling Hypermedia-Driven Applications:
162
163 HDAs can scale very well with respect to performance and feature count. They *can* scale with feature complexity,
164 with caveats. And, finally, the jury is still out on scaling with team size, although we can say that the HDA approach
165 tends to keep teams smaller and eliminate inter-team communication friction.