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.

This talk has been presented at TypeScript Congress 2023, check out the latest edition of this Tech Conference.

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
This talk discusses the usage of Microfrontends in Remix and introduces the Tiny Frontend library. Kazoo, a used car buying platform, follows a domain-driven design approach and encountered issues with granular slicing. Tiny Frontend aims to solve the slicing problem and promotes type safety and compatibility of shared dependencies. The speaker demonstrates how Tiny Frontend works with server-side rendering and how Remix can consume and update components without redeploying the app. The talk also explores the usage of micro frontends and the future support for Webpack Module Federation in Remix.
React's Most Useful Types
React Day Berlin 2023React Day Berlin 2023
21 min
React's Most Useful Types
Top Content
Watch video: React's Most Useful Types
Today's Talk focuses on React's best types and JSX. It covers the types of JSX and React components, including React.fc and React.reactnode. The discussion also explores JSX intrinsic elements and react.component props, highlighting their differences and use cases. The Talk concludes with insights on using React.componentType and passing components, as well as utilizing the react.element ref type for external libraries like React-Select.
Full Stack Components
Remix Conf Europe 2022Remix Conf Europe 2022
37 min
Full Stack Components
Top Content
RemixConf EU discussed full stack components and their benefits, such as marrying the backend and UI in the same file. The talk demonstrated the implementation of a combo box with search functionality using Remix and the Downshift library. It also highlighted the ease of creating resource routes in Remix and the importance of code organization and maintainability in full stack components. The speaker expressed gratitude towards the audience and discussed the future of Remix, including its acquisition by Shopify and the potential for collaboration with Hydrogen.
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
React and TypeScript have a strong relationship, with TypeScript offering benefits like better type checking and contract enforcement. Failing early and failing hard is important in software development to catch errors and debug effectively. TypeScript provides early detection of errors and ensures data accuracy in components and hooks. It offers superior type safety but can become complex as the codebase grows. Using union types in props can resolve errors and address dependencies. Dynamic communication and type contracts can be achieved through generics. Understanding React's built-in types and hooks like useState and useRef is crucial for leveraging their functionality.
Debugging JS
React Summit 2023React Summit 2023
24 min
Debugging JS
Top Content
Watch video: Debugging JS
Debugging JavaScript is a crucial skill that is often overlooked in the industry. It is important to understand the problem, reproduce the issue, and identify the root cause. Having a variety of debugging tools and techniques, such as console methods and graphical debuggers, is beneficial. Replay is a time-traveling debugger for JavaScript that allows users to record and inspect bugs. It works with Redux, plain React, and even minified code with the help of source maps.
Making JavaScript on WebAssembly Fast
JSNation Live 2021JSNation Live 2021
29 min
Making JavaScript on WebAssembly Fast
Top Content
WebAssembly enables optimizing JavaScript performance for different environments by deploying the JavaScript engine as a portable WebAssembly module. By making JavaScript on WebAssembly fast, instances can be created for each request, reducing latency and security risks. Initialization and runtime phases can be improved with tools like Wiser and snapshotting, resulting in faster startup times. Optimizing JavaScript performance in WebAssembly can be achieved through techniques like ahead-of-time compilation and inline caching. WebAssembly usage is growing outside the web, offering benefits like isolation and portability. Build sizes and snapshotting in WebAssembly depend on the application, and more information can be found on the Mozilla Hacks website and Bike Reliance site.

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.
Mastering advanced concepts in TypeScript
React Summit US 2023React Summit US 2023
132 min
Mastering advanced concepts in TypeScript
Top Content
Featured WorkshopFree
Jiri Lojda
Jiri Lojda
TypeScript is not just types and interfaces. Join this workshop to master more advanced features of TypeScript that will make your code bullet-proof. We will cover conditional types and infer notation, template strings and how to map over union types and object/array properties. Each topic will be demonstrated on a sample application that was written with basic types or no types at all and we will together improve the code so you get more familiar with each feature and can bring this new knowledge directly into your projects.
You will learn:- - What are conditional types and infer notation- What are template strings- How to map over union types and object/array properties.
Deep TypeScript Tips & Tricks
Node Congress 2024Node Congress 2024
83 min
Deep TypeScript Tips & Tricks
Top Content
Featured 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.
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.
Master JavaScript Patterns
JSNation 2024JSNation 2024
145 min
Master JavaScript Patterns
Featured Workshop
Adrian Hajdin
Adrian Hajdin
During this workshop, participants will review the essential JavaScript patterns that every developer should know. Through hands-on exercises, real-world examples, and interactive discussions, attendees will deepen their understanding of best practices for organizing code, solving common challenges, and designing scalable architectures. By the end of the workshop, participants will gain newfound confidence in their ability to write high-quality JavaScript code that stands the test of time.
Points Covered:
1. Introduction to JavaScript Patterns2. Foundational Patterns3. Object Creation Patterns4. Behavioral Patterns5. Architectural Patterns6. Hands-On Exercises and Case Studies
How It Will Help Developers:
- Gain a deep understanding of JavaScript patterns and their applications in real-world scenarios- Learn best practices for organizing code, solving common challenges, and designing scalable architectures- Enhance problem-solving skills and code readability- Improve collaboration and communication within development teams- Accelerate career growth and opportunities for advancement in the software industry
Building Your Own Custom Type System
React Summit 2024React Summit 2024
38 min
Building Your Own Custom Type System
Featured Workshop
Kunal Dubey
Kunal Dubey
I'll introduce the audience to a concept where they can have end-to-end type systems that helps ensure typesafety across the teams Such a system not only improves communication between teams but also helps teams collaborate effectively and ship way faster than they used to before. By having a custom type system, teams can also identify the errors and modify the API contracts on their IDE, which contributes to a better Developer Experience. The workshop would primarily leverage TS to showcase the concept and use tools like OpenAPI to generate the typesystem on the client side.