Generating Typed Code

Rate this content
Bookmark

For the past six at Rollbar the engineering team has been working tirelessly to migrate our legacy application to a modern Javascript tech stack. We’ve leveraged Next.js, GraphQL and a number of other JS tools to ship more features, make our dev team happier and achieve an impressive 7-fold reduction in our p99 app performance. I invite you to join me as I present the various techniques and architecture we choose to use to quickly migrate away from our legacy monolith.

FAQ

Rollbar's monolith tech stack is primarily built on Python Pyramid, a web framework. It also utilizes MySQL, Elasticsearch, and Clickhouse databases, with the frontend command written in React 16 and styled using Sass and CSS.

Rollbar decided to migrate to TypeScript to address challenges such as debugging complexity, inefficient code leading to performance issues, and difficulty in navigating through the monolithic code base. TypeScript offers type safety, compile-time optimizations, and improved performance.

Rollbar uses GraphQL Codegen to generate TypeScript code for both server-side and client-side applications. On the server side, it generates types for GraphQL resolvers. On the client side, it generates React query clients from GraphQL queries, ensuring type safety and simplifying the development process.

Rollbar's new tech stack includes Next.js, GraphQL, React Query, and TypeScript. This stack helps resolve issues related to the monolithic application, improves debugging, enhances performance with compile-time optimizations, and allows front-end and back-end developers to work more independently.

TypeScript improves Rollbar's developer experience by catching potential issues during compilation, enhancing code performance, and making it easier to navigate and use internal libraries, especially those with poor documentation. It supports parallel development among teams, reducing dependency.

Paul Serraino
Paul Serraino
22 min
21 Sep, 2023

Comments

Sign in or register to post your comment.

Video Summary and Transcription

Today, I'm going to be talking about how type generation helped reduce bugs and improve our developer experience at Rollbar. The Monolith tech stack is built primarily on Python Pyramid, a web framework that's similar to Django, Ruby on Rails, or Express. To address debugging, performance, and code navigation challenges, we migrated to a tech stack that includes TypeScript, Next.js, GraphQL, and React Query. Codegen is used to generate TypeScript code on both the server and client side, enhancing debugging, performance, and code navigation.

Available in Español: Generación de Código Tipado

1. Introduction to Rollbar Monolith and Tech Stack

Short description:

Today, I'm going to be talking about how type generation helped reduce bugs and improve our developer experience at Rollbar. I'll provide an overview of the architecture that we decided to implement. The Monolith tech stack is built primarily on Python Pyramid, a web framework that's similar to Django, Ruby on Rails, or Express.

Hello, everyone. Today, I'm going to be talking about how type generation helped reduce bugs and improve our developer experience at Rollbar. I'm Paul Sereno. I'm a senior software engineer at Rollbar. I have about 10 years of experience as a software developer, working on web-based applications, and I live in Austin, Texas.

For today's agenda, I'm going to first give a brief introduction into the Rollbar monolith. I'll talk about some of the technical challenges we experienced while maintaining the monolith code. And I'll explain why we made the decision to migrate our code base to TypeScript. Then I'm going to talk about the migration strategy into TypeScript, and I'll provide an overview of the architecture that we decided to implement. After that, I'll discuss how we were using GraphQL Code Gen at Rollbar, and I'll provide a few code examples that will demonstrate various ways we're using Code Gen on both the server side and client side of our application.

Okay, first let's go through the Monolith application. The Monolith tech stack is built primarily on Python Pyramid, a web framework that's similar to Django, Ruby on Rails, or Express. We're using a number of different database technologies like MySQL, Elasticsearch, and Clickhouse. The command is written in React 16, so there's no hooks and everything is styled using a mix of Sass and CSS.

2. Migrating to New Tech Stack

Short description:

Throughout the years, the Monolith has had 78 contributors, over 44,000 commits, and over 9,000 pull requests. Developing and deploying in a monolithic code base has its benefits, such as easier development and deployment processes. However, debugging, performance, and code navigation have been significant challenges. To address these issues, we decided to migrate to a newer tech stack that includes TypeScript, Next.js, GraphQL, and React Query. This tech stack allows us to leverage type safety, flexibility in backend migrations, and efficient API calls through React Query.

Throughout the years, the Monolith has had 78 contributors, over 44,000 commits, and over 9,000 pull requests, and is 11 years old. There are some benefits of working in a monolithic code base. It's much easier to develop in a monolithic code base, because there's often boilerplate code that developers can copy and paste and tweak to get something working faster. Developing a monolith application is sometimes easier if you can fit everything into a... Sorry about that.

Deploying a monolith application is sometimes easier because you can fit everything into a single Dockerfile. And code search is often a better experience in monolithic applications because a line of code that you'd like to search for is all in a single repository. So it's much easier to search for single lines of code.

Some of the challenges that we experience with working in our monolith applications have been debugging has been a big challenge because there's a lot of code that you have to read through to fully understand the root cause of certain issues. We use Rollbar ourselves to triage issues, and while the grouping features that Rollbar provides are nice, we still find it difficult to root cause some parts of the code base that are really complex. Performance is another issue with our monolithic code base, and it's mostly due to inefficient code. For example, things like making duplicate database calls and doing heavy post-processing on fetching data has been a pretty big bottleneck. We've also experienced issues with just navigating through code. It could sometimes take hours to fully understand how some things work. And given these issues, we decided to make the decision to migrate away from working in a monolithic application towards a newer tech stack.

And that tech stack includes TypeScript. So the new tech stack leverages Next.js, GraphQL, and React Query to help resolve some of the issues related to our monolith application. And of course, everything's written in TypeScript. The new tech stack that we're in the process of migrating to still uses parts of the monolithic application. We made those features from the monolith available through a number of internal API end points. The GraphQL server is essentially used as an API proxy that sits between our internal API and our front end application. And we made the decision to use GraphQL in this way because it not only provides TypeScript, but it not only provides type safety between the server and the client, but it also gives us flexibility in terms of back end migrations. For example, we're planning on placing some of the internal API end points with gRPC calls. In this proxy, architecture allows us to experiment with different back end solutions. All of our API calls from the front end are made through React Query. And the React Query client that we're using is completely generated from the GraphQL queries themselves. And I'll talk about that in a minute. But this setup has allowed us to get a lot of type safety into the front end. So I mentioned that we generate our front end client. So specifically we use a tool called GraphQL Codegen.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Scaling Up with Remix and Micro Frontends
Remix Conf Europe 2022Remix Conf Europe 2022
23 min
Scaling Up with Remix and Micro Frontends
Top Content
Do you have a large product built by many teams? Are you struggling to release often? Did your frontend turn into a massive unmaintainable monolith? If, like me, you’ve answered yes to any of those questions, this talk is for you! I’ll show you exactly how you can build a micro frontend architecture with Remix to solve those challenges.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
Remix is a web framework that gives you the simple mental model of a Multi-Page App (MPA) but the power and capabilities of a Single-Page App (SPA). One of the big challenges of SPAs is network management resulting in a great deal of indirection and buggy code. This is especially noticeable in application state which Remix completely eliminates, but it's also an issue in individual components that communicate with a single-purpose backend endpoint (like a combobox search for example).
In this talk, Kent will demonstrate how Remix enables you to build complex UI components that are connected to a backend in the simplest and most powerful way you've ever seen. Leaving you time to chill with your family or whatever else you do for fun.
TypeScript and React: Secrets of a Happy Marriage
React Advanced Conference 2022React Advanced Conference 2022
21 min
TypeScript and React: Secrets of a Happy Marriage
Top Content
TypeScript and React are inseparable. What's the secret to their successful union? Quite a lot of surprisingly strange code. Learn why useRef always feels weird, how to wrangle generics in custom hooks, and how union types can transform your components.
Making JavaScript on WebAssembly Fast
JSNation Live 2021JSNation Live 2021
29 min
Making JavaScript on WebAssembly Fast
Top Content
JavaScript in the browser runs many times faster than it did two decades ago. And that happened because the browser vendors spent that time working on intensive performance optimizations in their JavaScript engines.Because of this optimization work, JavaScript is now running in many places besides the browser. But there are still some environments where the JS engines can’t apply those optimizations in the right way to make things fast.We’re working to solve this, beginning a whole new wave of JavaScript optimization work. We’re improving JavaScript performance for entirely different environments, where different rules apply. And this is possible because of WebAssembly. In this talk, I'll explain how this all works and what's coming next.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
As developers, we spend much of our time debugging apps - often code we didn't even write. Sadly, few developers have ever been taught how to approach debugging - it's something most of us learn through painful experience.  The good news is you _can_ learn how to debug effectively, and there's several key techniques and tools you can use for debugging JS and React apps.
React's Most Useful Types
React Day Berlin 2023React Day Berlin 2023
21 min
React's Most Useful Types
Top Content
We don't think of React as shipping its own types. But React's types are a core part of the framework - overseen by the React team, and co-ordinated with React's major releases.In this live coding talk, we'll look at all the types you've been missing out on. How do you get the props type from a component? How do you know what ref a component takes? Should you use React.FC? And what's the deal with JSX.Element?You'll walk away with a bunch of exciting ideas to take to your React applications, and hopefully a new appreciation for the wonders of React and TypeScript working together.

Workshops on related topic

React, TypeScript, and TDD
React Advanced Conference 2021React Advanced Conference 2021
174 min
React, TypeScript, and TDD
Top Content
Featured WorkshopFree
Paul Everitt
Paul Everitt
ReactJS is wildly popular and thus wildly supported. TypeScript is increasingly popular, and thus increasingly supported.

The two together? Not as much. Given that they both change quickly, it's hard to find accurate learning materials.

React+TypeScript, with JetBrains IDEs? That three-part combination is the topic of this series. We'll show a little about a lot. Meaning, the key steps to getting productive, in the IDE, for React projects using TypeScript. Along the way we'll show test-driven development and emphasize tips-and-tricks in the IDE.
Best Practices and Advanced TypeScript Tips for React Developers
React Advanced Conference 2022React Advanced Conference 2022
148 min
Best Practices and Advanced TypeScript Tips for React Developers
Top Content
Featured Workshop
Maurice de Beijer
Maurice de Beijer
Are you a React developer trying to get the most benefits from TypeScript? Then this is the workshop for you.In this interactive workshop, we will start at the basics and examine the pros and cons of different ways you can declare React components using TypeScript. After that we will move to more advanced concepts where we will go beyond the strict setting of TypeScript. You will learn when to use types like any, unknown and never. We will explore the use of type predicates, guards and exhaustive checking. You will learn about the built-in mapped types as well as how to create your own new type map utilities. And we will start programming in the TypeScript type system using conditional types and type inferring.
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
React Day Berlin 2022React Day Berlin 2022
86 min
Using CodeMirror to Build a JavaScript Editor with Linting and AutoComplete
Top Content
WorkshopFree
Hussien Khayoon
Kahvi Patel
2 authors
Using a library might seem easy at first glance, but how do you choose the right library? How do you upgrade an existing one? And how do you wade through the documentation to find what you want?
In this workshop, we’ll discuss all these finer points while going through a general example of building a code editor using CodeMirror in React. All while sharing some of the nuances our team learned about using this library and some problems we encountered.
Deep TypeScript Tips & Tricks
Node Congress 2024Node Congress 2024
83 min
Deep TypeScript Tips & Tricks
Top Content
Workshop
Josh Goldberg
Josh Goldberg
TypeScript has a powerful type system with all sorts of fancy features for representing wild and wacky JavaScript states. But the syntax to do so isn't always straightforward, and the error messages aren't always precise in telling you what's wrong. Let's dive into how many of TypeScript's more powerful features really work, what kinds of real-world problems they solve, and how to wrestle the type system into submission so you can write truly excellent TypeScript code.
Testing Web Applications Using Cypress
TestJS Summit - January, 2021TestJS Summit - January, 2021
173 min
Testing Web Applications Using Cypress
WorkshopFree
Gleb Bahmutov
Gleb Bahmutov
This workshop will teach you the basics of writing useful end-to-end tests using Cypress Test Runner.
We will cover writing tests, covering every application feature, structuring tests, intercepting network requests, and setting up the backend data.
Anyone who knows JavaScript programming language and has NPM installed would be able to follow along.
Build a powerful DataGrid in few hours with Ag Grid
React Summit US 2023React Summit US 2023
96 min
Build a powerful DataGrid in few hours with Ag Grid
WorkshopFree
Mike Ryan
Mike Ryan
Does your React app need to efficiently display lots (and lots) of data in a grid? Do your users want to be able to search, sort, filter, and edit data? AG Grid is the best JavaScript grid in the world and is packed with features, highly performant, and extensible. In this workshop, you’ll learn how to get started with AG Grid, how we can enable sorting and filtering of data in the grid, cell rendering, and more. You will walk away from this free 3-hour workshop equipped with the knowledge for implementing AG Grid into your React application.
We all know that rolling our own grid solution is not easy, and let's be honest, is not something that we should be working on. We are focused on building a product and driving forward innovation. In this workshop, you'll see just how easy it is to get started with AG Grid.
Prerequisites: Basic React and JavaScript
Workshop level: Beginner