Latest / CyberCode Academy / Course 37 - Building Web Apps with Ruby On Rails | Episode 18:Navigating GraphQL and the Graphiti Middle Ground
Transcript
- 0:00Speaker 1: I mean, I want you to start by picturing a
- 0:03Speaker 1: very specific, incredibly frustrating moment in your workflow. You know,
- 0:07Speaker 1: you're testing an application your building.
- 0:09Speaker 2: Oh yeah, we've all been there, right.
- 0:10Speaker 1: Maybe it's a complex internal dashboard or like a heavy
- 0:13Speaker 1: mobile client, you tap a view and well nothing, just
- 0:18Speaker 1: a spinning indicator.
- 0:19Speaker 2: The dreaded infinite spinner.
- 0:21Speaker 1: Exactly. You check your network monitor and the connection is
- 0:24Speaker 1: blazing fast. The device has plenty of memory, So what
- 0:27Speaker 1: gives most of the time, the bottleneck isn't the hardware,
- 0:30Speaker 1: and it isn't the network speed itself.
- 0:34Speaker 2: It rarely is.
- 0:35Speaker 1: The real culprit is the architectural negotiation happening under the hood.
- 0:39Speaker 1: It's the way your application is actually asking the server
- 0:42Speaker 1: for data.
- 0:42Speaker 2: Yeah, it is the I mean, it's the invisible structural
- 0:45Speaker 2: highway of the web. We spend so much time, you know,
- 0:49Speaker 2: optimizing front end renders and tweaking database indexes, But that
- 0:53Speaker 2: middle layer, the actual data fetching paradigm, often dictates the
- 0:57Speaker 2: performance ceiling of your entire application, And historically, the conventions
- 1:01Speaker 2: we've relied on to negotiate that data transfer just haven't
- 1:05Speaker 2: always scaled elegantly with modern application demands.
- 1:09Speaker 1: Right, which is exactly our mission for this deep dive today.
- 1:13Speaker 1: We are going to decode those hidden bottlenecks and modern
- 1:16Speaker 1: data fetching. We're going on a journey of like architectural.
- 1:20Speaker 2: Problem solving, starting with the classics.
- 1:22Speaker 1: Yep, starting with the rigid constraints of traditional rest, moving
- 1:26Speaker 1: into the wild highly decoupled era where graphql put the
- 1:30Speaker 1: client entirely in the driver's seat. Oh, the wild West,
- 1:33Speaker 1: yeah exactly, And finally we'll be unpacking this fascinating Goldilocks
- 1:38Speaker 1: framework called graffiti. By the end of this you'll have
- 1:40Speaker 1: a crystal clear conceptual roadmap of how these data layer
- 1:44Speaker 1: architectures actually function and more importantly, the specific trade offs
- 1:48Speaker 1: they force you to make.
- 1:49Speaker 2: And we really need to look at the mechanisms driving
- 1:51Speaker 2: these shifts.
- 1:52Speaker 1: Right.
- 1:52Speaker 2: Technology is highly evolutionary. I mean, frameworks aren't just born
- 1:56Speaker 2: in a vacuum. It come from pain exactly. They are
- 1:58Speaker 2: engineered directly out of the pain points and the exhausted
- 2:01Speaker 2: developer hours caused by whatever the previous standard was. So
- 2:05Speaker 2: to understand where we are, we have to deeply understand
- 2:08Speaker 2: the mechanical failures of what we left behind.
- 2:11Speaker 1: Okay, let's unpack this by starting with the baseline for
- 2:14Speaker 1: a massive chunk of web history. The absolute gold standard
- 2:18Speaker 1: for client server architecture was REST.
- 2:20Speaker 2: Right.
- 2:21Speaker 1: But the issue with REST, especially as client applications got
- 2:24Speaker 1: vastly more complex, was that it relied on a completely rigid,
- 2:27Speaker 1: server dictated contract.
- 2:29Speaker 2: That's the core friction point. Really, a REST API is
- 2:33Speaker 2: fundamentally a set of pre compiled end points, dictated entirely
- 2:36Speaker 2: by the back end architecture.
- 2:37Speaker 1: The back end calls the shots exactly.
- 2:39Speaker 2: The client application has zero agency over the shape of
- 2:42Speaker 2: the data payload it receives. The server exposes a pre
- 2:45Speaker 2: defined resource URL, and the client simply has to accept
- 2:48Speaker 2: whatever Jason blob the back end engineers decided to tie
- 2:51Speaker 2: to that URL.
- 2:52Speaker 1: Which leads directly to the most notorious architectural.
- 2:55Speaker 2: Flaw of REST, the overfetching problem.
- 2:57Speaker 1: Yes, I love using the set menu analogy for this.
- 3:01Speaker 1: REST is like going to a highly rigid fine dining
- 3:04Speaker 1: restaurant where the only option is a pre set five
- 3:07Speaker 1: course tasting menu. Right. It doesn't matter if your client
- 3:10Speaker 1: application only needs a glass of water to render a
- 3:13Speaker 1: specific UI component. You hit that endpoint and the server
- 3:16Speaker 1: is going to bring out the soup the salad, the steak,
- 3:19Speaker 1: the sides, and the dessert.
- 3:20Speaker 2: It's a great analogy because it just highlights the wasted resources.
- 3:24Speaker 2: Let's say you have a mobile view that only needs
- 3:26Speaker 2: to render a user's username and their avatar URL. Pretty
- 3:30Speaker 2: standard requirement, right, So to get that, your client pings
- 3:33Speaker 2: the slash users Slash one twenty three end point, but
- 3:37Speaker 2: the back end controller for that endpoint is serialized to
- 3:40Speaker 2: return the entire user object.
- 3:41Speaker 1: Oh boy, so everything everything.
- 3:43Speaker 2: Their address, their encrypted password hashes, their billing history, their
- 3:47Speaker 2: last fifty session tokens. Wow, your client is forced to
- 3:50Speaker 2: download a like fifty kiloby Jason payload parts the entire
- 3:55Speaker 2: tree into memory, extract the two strings it actually needs,
- 3:58Speaker 2: and throw the rest away.
- 3:59Speaker 1: That is just so inefficient.
- 4:01Speaker 2: It is. You're burning bandwidth, your spiking memory usage on
- 4:05Speaker 2: the device, and you're draining the user's battery all to
- 4:08Speaker 2: throw away ninety eight percent of the payload.
- 4:11Speaker 1: And it's not just the payload bloat, you know, it's
- 4:13Speaker 1: the tight coupling that makes scaling a nightmare.
- 4:16Speaker 2: Oh absolutely, Like, if the front.
- 4:18Speaker 1: End team decides to add a badge to that mobile
- 4:20Speaker 1: view showing the user's current project status, they can't just
- 4:24Speaker 1: fetch it. Nope, they have to file a ticket with
- 4:26Speaker 1: the back end team to either bloat that existing user
- 4:30Speaker 1: payload even more or spin up a completely new custom endpoint.
- 4:34Speaker 1: You end up in versioning.
- 4:35Speaker 2: Hell yeah, maintaining a V one slash users for the
- 4:39Speaker 2: old app build and a V two slash users for
- 4:42Speaker 2: the new one. It's exhausting, precisely. And we haven't even
- 4:45Speaker 2: touched on the lack of strict type safety in traditional
- 4:48Speaker 2: REST payloads.
- 4:49Speaker 1: Oh right, because there's no inherent schema exactly.
- 4:52Speaker 2: Standard REST doesn't intrinsically enforce a schema contract that the
- 4:55Speaker 2: client can read. The server has to defensively parse and
- 4:59Speaker 2: validate every the incoming piece of Jason data, eating up
- 5:02Speaker 2: compute cycles.
- 5:03Speaker 1: So you end up writing massive amounts of external documentation yeah, like.
- 5:07Speaker 2: Swagger or open API specs, just to manually communicate what
- 5:11Speaker 2: data types the client is supposed to send and receive.
- 5:14Speaker 1: So if REST is this rigid, heavily coupled set menu
- 5:18Speaker 1: that waste bandwidth and requires constant versioning, developers naturally realized
- 5:22Speaker 1: they needed a paradigm shift.
- 5:24Speaker 2: They needed to change the rules right.
- 5:26Speaker 1: They needed a way to let the client dictate the
- 5:29Speaker 1: shape of the response a la cart ordering, and that
- 5:33Speaker 1: burning needs. Shifting the configuration power from the server engineers
- 5:37Speaker 1: to the client engineers brings us directly to the creation
- 5:40Speaker 1: of graphql.
- 5:41Speaker 2: Graph Ql fundamentally flits the architectural script. I mean, it
- 5:45Speaker 2: completely decouples the client's data requirements from the server's database structure.
- 5:49Speaker 1: Okay, how so, Well.
- 5:50Speaker 2: The client is empowered to request precisely the exact nodes
- 5:53Speaker 2: of data it needs across multiple domains in a single network.
- 5:57Speaker 1: Request, meaning overfetching is completely eliminated.
- 5:59Speaker 2: By the entirely. But to understand how it physically does
- 6:03Speaker 2: this without breaking the server, we have to look at
- 6:05Speaker 2: its three main pillars.
- 6:06Speaker 1: All right, let's break them down.
- 6:07Speaker 2: The foundational pillar is the schema. Unlike rest, where the
- 6:11Speaker 2: structure is loosely implied by the endpoint, a graph ql
- 6:15Speaker 2: back end is defined by a strongly typed directed graph.
- 6:19Speaker 1: So it's like a map exactly.
- 6:21Speaker 2: The schema explicitly maps out every possible entity users, projects, milestones,
- 6:27Speaker 2: and exactly how they relate to one another via edges.
- 6:30Speaker 1: And because this schema is highly introspectable, the client actually
- 6:34Speaker 1: downloads this map in advance.
- 6:36Speaker 2: Exactly, which enables the second pillar, which is the query
- 6:38Speaker 2: language itself. Because the client has the full map, it
- 6:41Speaker 2: sends a highly specific abstract syntax tree in AST back
- 6:45Speaker 2: to the server.
- 6:46Speaker 1: Wait, so the client sends a tree.
- 6:47Speaker 2: Yeah. The client query literally mimics the shape of the
- 6:50Speaker 2: Jason response at once, basically says give me user one
- 6:53Speaker 2: twenty three and traverse the graph to their projects, but
- 6:56Speaker 2: only give me the titles.
- 6:57Speaker 1: Oh I see.
- 6:58Speaker 2: And then the third pillar is the runtime on this,
- 7:00Speaker 2: which validates that incoming AST against the schema and executes
- 7:04Speaker 2: the data fetching.
- 7:05Speaker 1: What's fascinating here is because the client is validating against
- 7:08Speaker 1: the schema locally before it even opens a network connection
- 7:11Speaker 1: type errors are caught instantly.
- 7:13Speaker 2: Yes, that early validation is huge. Right.
- 7:16Speaker 1: If the front end tries to pass a string into
- 7:19Speaker 1: a field that the schema strictly defines as an integer,
- 7:22Speaker 1: the client side GRAPHQL library throws a fatal error and
- 7:26Speaker 1: prevents the network.
- 7:27Speaker 2: Trip entirely saves a ton of overhead.
- 7:29Speaker 1: Plus you're traversing massive relational associations in one request, effectively
- 7:35Speaker 1: killing the underfetching problem too.
- 7:37Speaker 2: It acts as a self documenting, mathematically verifiable map of
- 7:41Speaker 2: your entire system. You don't need external wikis. The schema
- 7:45Speaker 2: is the absolute source of truth.
- 7:47Speaker 1: But wait, I have to push back here because this
- 7:49Speaker 1: is where the theory always hits a wall in production.
- 7:51Speaker 2: Okay, let's hear it.
- 7:52Speaker 1: If the client is suddenly empowered to send these massive,
- 7:55Speaker 1: infinitely nested, totally custom data requests, how does the server
- 8:00Speaker 1: out them? I mean, in rest, we had dedicator controllers
- 8:03Speaker 1: tuned for specific URLs.
- 8:05Speaker 2: Right gettee slash projects hits the project's controller.
- 8:08Speaker 1: Exactly, which runs a highly optimized SEQL query. If graph
- 8:12Speaker 1: ul allows the client to ask for users, projects, and
- 8:14Speaker 1: billing data all at once, where does the request actually go?
- 8:17Speaker 1: How does the server avoid just choking on the routing logic.
- 8:20Speaker 2: That is the pivotal architectural shift. To answer that, we
- 8:24Speaker 2: have to look under the hood at the actual machinery
- 8:27Speaker 2: of a graph ul request. Unlike REST, which utilizes the
- 8:31Speaker 2: entire spectrum of HTTP verbs and distinct URL paths, graph
- 8:35Speaker 2: ql typically abandons all of that, all of it pretty much.
- 8:39Speaker 2: It exposes one single endpoint. It's usually a post request
- 8:43Speaker 2: to slash graphque.
- 8:44Speaker 1: Okay, so we lose the routing layer entirely. Let me
- 8:47Speaker 1: try an analogy here instead of walking through a building
- 8:49Speaker 1: and going to different departmental offices for different requests. Graphql
- 8:53Speaker 1: is like hiring a highly skilled general contractor.
- 8:56Speaker 2: I like where this is going.
- 8:57Speaker 1: You hand them one massive, complex blueprint the query at
- 9:01Speaker 1: the front door. You don't care how the house gets built.
- 9:03Speaker 1: You just trust the contractor to read the blueprint, hire
- 9:06Speaker 1: the specific plumbers and electricians, and hand you the keys
- 9:09Speaker 1: when it's done.
- 9:10Speaker 2: That is highly accurate. On your back end, that general
- 9:12Speaker 2: contractor is the graph q al controller. It typically has
- 9:15Speaker 2: a single execute action that intercepts that post request.
- 9:19Speaker 1: And what's inside that request.
- 9:20Speaker 2: The payload contains three critical parameters. First, the query itself,
- 9:25Speaker 2: that string representing the ast blueprint, Second the variables, a
- 9:29Speaker 2: separate Jason dictionary containing the dynamic arguments like the specific
- 9:34Speaker 2: user ID which prevents injection attacks smart and third, an
- 9:39Speaker 2: optional but absolutely vital parameter called operation name.
- 9:43Speaker 1: Oh I imagine operation name is critical for application performance monitoring.
- 9:47Speaker 2: Why is that?
- 9:47Speaker 1: Well, if every single piece of traffic in your entire
- 9:51Speaker 1: system is just a post to slash graph keel, your
- 9:54Speaker 1: data dog or neur Relic dashboards would just be a
- 9:57Speaker 1: completely useless, uniform sea of ide dentical requests you'd have
- 10:01Speaker 1: no idea which queries were actually slowing down the database.
- 10:04Speaker 2: Spot on with that operation name tagged in the payload
- 10:07Speaker 2: debugging system, bottlenecks is virtually impossible. The controller also initializes
- 10:11Speaker 2: a context TASH.
- 10:12Speaker 1: What does that do?
- 10:13Speaker 2: This acts like a secure backstage pass attached to the
- 10:16Speaker 2: execution context. You inject things like the authentication token or
- 10:19Speaker 2: the current user object into the context so that deep
- 10:22Speaker 2: down the graph, individual nodes can check permissions without having
- 10:25Speaker 2: to pass the user object through every single function.
- 10:28Speaker 1: So the general contractor has the blueprint, the variables, and
- 10:31Speaker 1: the security context. How do they actually build the response?
- 10:35Speaker 1: Because in graphql, we aren't using HTTP get or post
- 10:40Speaker 1: to determine if we are reading or writing.
- 10:42Speaker 2: Data right, the protocol intent is entirely decoupled from the
- 10:45Speaker 2: HTTP transport layer. Instead, graphql defines operation types within the
- 10:51Speaker 2: query language.
- 10:51Speaker 1: Itself, so it's baked into the string exactly.
- 10:55Speaker 2: A quirdy operation is strictly for fetching data resolving the
- 10:58Speaker 2: graph without side effects. A mutation operation is explicitly for
- 11:02Speaker 2: altering state, creating, updating, or deleting records, but the real
- 11:06Speaker 2: heavy lifting for both of these operations is delegated to resolvers.
- 11:09Speaker 1: Ah, the plumbers and electricians from our analogy exactly.
- 11:13Speaker 2: Resolvers are essentially isolated, pure functions attached to every single
- 11:16Speaker 2: field in your schema. When the execution engine parses your blueprint,
- 11:19Speaker 2: it walks down the tree and triggers the specific resolver
- 11:21Speaker 2: for each field.
- 11:22Speaker 1: Okay, so it steps through it.
- 11:23Speaker 2: Yeah. If you ask for a user, the user resolver
- 11:26Speaker 2: fires and hits the database. If you nested projects inside
- 11:31Speaker 2: that user, the engine then passes the resolves user object
- 11:34Speaker 2: down to the project resolver, which fetches the associated projects.
- 11:38Speaker 1: That makes sense.
- 11:38Speaker 2: It recursively resolves every node until the final JSON tree
- 11:43Speaker 2: perfectly matches the shape the client requested.
- 11:45Speaker 1: Here's where it gets really interesting, though, because that recursive
- 11:48Speaker 1: resolution sounds incredibly elegant in theory, but in practice, infinite
- 11:54Speaker 1: flexibility gives front end developers an infinite amount of rope
- 11:58Speaker 1: to hang the back end with.
- 11:59Speaker 2: It really does.
- 12:00Speaker 1: The general contractor analogy breaks down when the client asks
- 12:02Speaker 1: for a house with ten thousand custom bathrooms. Graphql tried
- 12:06Speaker 1: so hard to fix the rigid constraints of rest that
- 12:09Speaker 1: it abandoned the fundamental conventions that make web infrastructure scalable.
- 12:12Speaker 2: You've hit on the exact reason developers eventually experienced graph
- 12:16Speaker 2: QOL fatigue. The zero sum decoupling is a double edged sword.
- 12:20Speaker 2: Let's look at the n plus one database problem, which
- 12:23Speaker 2: is the most notorious performance killer in a graph QOL architecture.
- 12:26Speaker 1: Right. Because resolvers are completely isolated functions, they don't inherently
- 12:29Speaker 1: know what other resolvers are doing precisely.
- 12:32Speaker 2: Let's say your client asks for a list of one
- 12:36Speaker 2: hundred users, and nested inside that query, it asks for
- 12:40Speaker 2: the avatar URL for each user.
- 12:42Speaker 1: It seems like a basic request right.
- 12:45Speaker 2: In rest, a back end engineer would write a single
- 12:47Speaker 2: optimized SQL query with the joy eind statement to pull
- 12:51Speaker 2: all one hundred users and their avatars from the database
- 12:53Speaker 2: in one single trip super fast. But in graphkeol, the
- 12:56Speaker 2: execution engine hits the user resolver once fetching a hundred users,
- 13:01Speaker 2: Then it walks down the tree and triggers the avatar
- 13:03Speaker 2: resolver independently for each of those hundred users.
- 13:06Speaker 1: Wait, so you end up hitting your database one hundred
- 13:08Speaker 1: and one times just to load a single page.
- 13:10Speaker 2: YEP one query for the users and one hundred separate
- 13:12Speaker 2: queries for the avatars.
- 13:13Speaker 1: Oh wow, that completely crushes your database connection.
- 13:16Speaker 2: Pool, and to fix it, back end developers are forced
- 13:18Speaker 2: to write massive amounts of complex boilerplate code, implementing batching
- 13:22Speaker 2: mechanisms like data loaders, just to artificially stitch those isolated
- 13:25Speaker 2: database calls back together.
- 13:27Speaker 1: That sounds like a nightmare.
- 13:28Speaker 2: It's an incredible amount of manual overhead just to achieve
- 13:32Speaker 2: the basic performance that rest gave you out of.
- 13:34Speaker 1: The box And speaking of abandoning out of the box features,
- 13:37Speaker 1: the single endpoint architecture completely destroys standard HTTP caching. Oh absolutely,
- 13:43Speaker 1: the entire Internet. You know, CDNs, proxy servers, browser caches
- 13:47Speaker 1: is built on the premise of caching unique URLs. If
- 13:50Speaker 1: I get slash projects slash one twenty three, the network
- 13:54Speaker 1: layer can cash that response. But if my client is
- 13:57Speaker 1: just firing massive PWIS bodies to slash graft call, the
- 14:01Speaker 1: infrastructure is blind to what data is actually moving.
- 14:04Speaker 2: It's a massive architectural regression. To get cashing back, you
- 14:07Speaker 2: have to bypass the network layer entirely and install incredibly
- 14:10Speaker 2: heavy complex client side caching libraries like Apollo.
- 14:13Speaker 1: Client, which is more overhead.
- 14:14Speaker 2: Exactly, you have to manually normalize the cache and the
- 14:17Speaker 2: device based on entity IDs, you're essentially forcing the front
- 14:20Speaker 2: end application to manage a highly complex localized database just
- 14:24Speaker 2: to avoid redundant network trips.
- 14:26Speaker 1: Not to mention the loss of simple conventions in REST,
- 14:29Speaker 1: Creating a resource is universally a post to the plural
- 14:32Speaker 1: resource name in graphql, because it's a blank canvas, developers
- 14:37Speaker 1: argue endlessly overnaming conventions is.
- 14:40Speaker 2: The mutation called ad project, creed project, or insert project.
- 14:43Speaker 1: Exactly you lose the predictable standardization of HTTP. So teams
- 14:48Speaker 1: realized they were exhausted. They loved the Olikarte querying power
- 14:52Speaker 1: of graphql, but they desperately missed the caching, the predictable routing,
- 14:56Speaker 1: and the optimized database querying of REST. They needed a synthesis, and.
- 15:01Speaker 2: That synthesis is exactly what Graffiti Spill with an I
- 15:04Speaker 2: at the end was engineered to achieve. Graffiti is a
- 15:07Speaker 2: framework designed to marry the intuitive, standardized HTDP conventions of
- 15:11Speaker 2: traditional REST with the surgical dynamic query flexibility of Graphql.
- 15:16Speaker 1: If we connect this to the bigger picture, graffiti essentially
- 15:19Speaker 1: acts as a highly intelligent translation layer. But how does
- 15:22Speaker 1: it actually merge these two opposing paradigms without just reverting
- 15:26Speaker 1: back to rest's rigid overfetching.
- 15:28Speaker 2: It does this by introducing a standardized resource layer and
- 15:31Speaker 2: a graffiti architecture. The resource sits between your HTTP controller
- 15:35Speaker 2: and you're underlying OARM your database models. Okay, this resource
- 15:40Speaker 2: strictly defines the schema, the relationships, and what data is
- 15:44Speaker 2: allowed to be exposed, much like a graphqel schema.
- 15:46Speaker 1: But unlike graphql, Graffiti respects the URL routing layer. We
- 15:51Speaker 1: get our distinct endpoints back.
- 15:53Speaker 2: That's the key Graffiti brings back Slash projects, slash users,
- 15:57Speaker 2: slash organizations because you were using standard HTTP get requests
- 16:02Speaker 2: to distinct URLs, Your CDN, your load balancers, and your
- 16:06Speaker 2: browser cache immediately start working again automatically. You regain the
- 16:11Speaker 2: entire internets built in caching infrastructure with zero custom configuration.
- 16:15Speaker 1: Okay, but if I had graphee slash users, aren't I
- 16:18Speaker 1: just getting the massive five course meal? Again? Where's the
- 16:21Speaker 1: graph ql flexibility? I want to know the mechanism that
- 16:23Speaker 1: allows the client to shape the payload.
- 16:25Speaker 2: The flexibility is reinjected through a deeply standardized interpretation of
- 16:28Speaker 2: standard HTP query parameters. The graffiti resource layer acts as
- 16:32Speaker 2: a compiler.
- 16:33Speaker 1: How does that look. In practice, when.
- 16:35Speaker 2: Your client hits slash users, it appends query parameters formatted
- 16:39Speaker 2: to a specific specification, specifically the Jason API specification. If
- 16:44Speaker 2: you only want the username, you append question mark fields
- 16:47Speaker 2: bracket users bracket equals username got it. If you want
- 16:51Speaker 2: to deeply nest their projects, you append question mark include
- 16:54Speaker 2: equals projects.
- 16:54Speaker 1: So instead of passing an AST in a posts body,
- 16:57Speaker 1: the client constructs the exact same relation requirements right inside
- 17:01Speaker 1: the URL string exactly. But wait, how does graffiti avoid
- 17:05Speaker 1: the n plus one database problem that plagues graphql. If
- 17:08Speaker 1: it's parsing mested includes from the URL, doesn't it still
- 17:11Speaker 1: have to fire multiple database queries.
- 17:13Speaker 2: This is where the resource layer really shines. Because Graffiti
- 17:17Speaker 2: isn't executing isolated resolvers node by node like graphql. It
- 17:21Speaker 2: has total context of the entire request upfront.
- 17:23Speaker 1: Oh, because it reads the whole URL at once.
- 17:26Speaker 2: Yes, the resource layer intercepts the URL parameters, validates them
- 17:29Speaker 2: against its internal schema to ensure the client is allowed
- 17:32Speaker 2: to request those fields, and then it dynamically compiles a single,
- 17:36Speaker 2: highly optimized, eager loaded SQL query to your database.
- 17:39Speaker 1: That is brilliant. It reads the URL, builds an internal
- 17:43Speaker 1: ast and max it directly to the orm's eager loading mechanisms. YEP,
- 17:48Speaker 1: So if I ask for one hundred users and their
- 17:50Speaker 1: avatars via an include parameter, Graffiti executes a single sequel
- 17:54Speaker 1: join under the hood. No data loader is required, no
- 17:57Speaker 1: custom boiler plate exactly.
- 17:59Speaker 2: You get the strict type safety and a la carte
- 18:01Speaker 2: fetching of graph ql, but you retain the zero configuration caching,
- 18:05Speaker 2: the standardized RESTful routing, and the deeply optimized database querying
- 18:10Speaker 2: that made traditional web architecture so robust.
- 18:12Speaker 1: It's the best of both worlds.
- 18:13Speaker 2: Features like cursor based pagination, sorting, and complex filtering are
- 18:17Speaker 2: all handled automatically by the resource layer, simply by reading
- 18:20Speaker 2: the URL parameters.
- 18:22Speaker 1: So what does this all mean for you listening at home?
- 18:24Speaker 1: We've traveled from the incredibly strict, heavily coupled contracts of
- 18:28Speaker 1: traditional rest APIs, where the server forced the client to
- 18:31Speaker 1: take whatever bloated payload.
- 18:32Speaker 2: It decided as send the five course meal.
- 18:34Speaker 1: Right, and then we watched the pendulum swing violently to
- 18:37Speaker 1: the opposite extreme, the absolute decouple everything freedom and honestly,
- 18:41Speaker 1: the architectural chaos of graphql's single endpoint execution the Wild West,
- 18:47Speaker 1: and finally we've found a highly pragmatic balance with Graffiti's
- 18:51Speaker 1: clever resource model. It's a perfect case study demonstrating that
- 18:55Speaker 1: in software engineering there are no silver bullets, there are
- 18:58Speaker 1: only trade offs. Always, the master stroke of architecture is
- 19:02Speaker 1: knowing how to balance the reliable conventions back end developers
- 19:05Speaker 1: need with the granular configurations client applications demand.
- 19:09Speaker 2: This raises an important question though, about where the pendulum
- 19:13Speaker 2: swings next. We've gone from server dictated to client dictuted
- 19:17Speaker 2: to a hybrid synthesis. But as edge computing becomes more prevalent,
- 19:21Speaker 2: and as AI becomes deeply integrated into infrastructure orchestration, will
- 19:25Speaker 2: we eventually move away from pre defined APIs entirely.
- 19:28Speaker 1: Oh, that is a wild but totally logical thought. Imagine
- 19:31Speaker 1: a near future where a predictive AI model sits at
- 19:34Speaker 1: the edge network acting as an ultra intelligent resource.
- 19:37Speaker 2: Layer, is analyzing everything on the fly.
- 19:39Speaker 1: Yeah, it analyzes your applications telemetry in real time, dynamically
- 19:44Speaker 1: spins up bespoke highly optimized data endpoints on the fly
- 19:48Speaker 1: based on what its neural network predicts the user's going
- 19:50Speaker 1: to tap on next, and then dissolves those endpoints the
- 19:53Speaker 1: moment the session ends. Wow, no static contracts, no rigid schemas,
- 19:57Speaker 1: just pure predictive state transfer.
- 20:00Speaker 2: It's a fascinating paradigm to consider. The infrastructure would shift
- 20:04Speaker 2: from being responsive to being entirely anticipatory. But until we
- 20:09Speaker 2: are deploying AI generated ephemeral endpoints, we have to master
- 20:13Speaker 2: the paradigms we currently have.
- 20:15Speaker 1: Very true, and speaking of mastery, I want to leave
- 20:17Speaker 1: you with a quick review exercise to solidify what we've
- 20:20Speaker 1: unpacked in this deep dive today. Imagine your tasked with
- 20:23Speaker 1: architecting the data layer for a massive logistics dashboard.
- 20:27Speaker 2: A heavy application, very heavy.
- 20:29Speaker 1: The client view needs to aggressively cache a user's static
- 20:32Speaker 1: profile data, but simultaneously display their last fifty freight orders,
- 20:37Speaker 1: filter those orders by dynamic date ranges, and eagerly load
- 20:41Speaker 1: the real time GPS tracking coordinates for each order.
- 20:44Speaker 2: It's a lot of moving parts.
- 20:45Speaker 1: Based on the mechanisms we explored today, which paradigm rest
- 20:49Speaker 1: GRAPHQL or graffiti would you deploy to build this and
- 20:52Speaker 1: specifically what exact architectural features of that paradigm drove your decision.
- 20:58Speaker 2: It's the perfect architectural stress test. Really, you have to
- 21:01Speaker 2: weigh the heavy caching requirements against the need for complex,
- 21:04Speaker 2: nested data retrieval and dynamic filtering exactly.
- 21:08Speaker 1: Think critically about the trade offs, because the next time
- 21:11Speaker 1: you tap an application and the data populates instantly without
- 21:13Speaker 1: that frustrating spinning circle, you won't just see a fast UI.
- 21:17Speaker 1: You'll be able to visualize the exact architectural machinery executing
- 21:21Speaker 1: seamlessly beneath the surface.