Skip to main content

Posts

Let's build our own online multiplayer chess game

Greetings! Chess is a hobby I enjoy, and as a chess fan, I often play online at chess.com. But you know what's even more thrilling? Creating our very own online chess game! I'm excited to share my experience with anyone interested! Source Code: GitHub (slmanju) Final result (using two browser windows) Chess game Chess is a complex board game played by two players. When a player makes a valid move we need to make it appear on other players board. What else, pieces, rules, communication, and lots of complex things are happening. I don't want to reinvent such complex things when things are free. Aha... the free stuff It's challenging to create all the necessary elements from scratch. Why go through the trouble when there are plenty of excellent free resources readily available? Let's make use of what's already out there. Chess pieces - wikimedia Chess rule - chess.js Chess board - chessboard.

Case study: Design a solution for long-running requests

Greetings As developers, we often aim to deliver APIs with minimal latency, typically in just a few milliseconds. However, it's important to acknowledge that not all customer requirements are alike. There are scenarios where we must tackle intricate computations that can extend over many minutes. Let's explore solutions for addressing such use cases. Problem statement The user expects to view the outcome of a complex computation, which requires more than 5 minutes to complete. Initial design We can outline our initial architecture by offering either a REST or GraphQL API that waits for the computation to conclude. The primary limitation of this design is that it blocks the server thread, which can lead to the exhaustion of server resources. Additionally, the user remains uninformed about the ongoing process. Improving with an Async Job and Polling Rather than waiting for the calculation to complete, we can utilize a separate thread and promptly return from the initial request.

Enhancing Node.js Microservices Performance through Connection Keep-Alive

Greetings! Efficient performance is a crucial non-functional requirement in modern applications. Customers can become easily frustrated and may seek alternative solutions if performance falls short. As developers, it is our responsibility to ensure that performance meets the required standards. I'd like to highlight a common mistake that developers might make if they are not familiar with the underlying theory. While the focus here is primarily on Node.js, the principles apply more broadly. Microservices leverage diverse technologies, and Node.js is a good candidate for API Gateways/ Proxy servers. These gateways play a key role in routing traffic to the underlying downstream microservices. Understanding this dynamic is both interesting and essential when working with Node.js. Note: In Node.js 19, agent keep-alive is now enabled by default. The Problem When incorporating libraries, developers often stick to default configurations or modify only the apparent settings. This approac

Understand and Build a GraphQL Federated API Gateway with Apollo and Nest

Greetings GraphQL revolutionized modern API development by addressing issues in REST through a unified interface. While GraphQL is well-suited for building monolithic services, modern applications are often complex and developed using the microservices architecture. How can we harness GraphQL to provide a unified API in a microservices application? This is where GraphQL federation comes in to solve the problem. Complete source code -  Nest GraphQL Federation Challenges faced in REST API Before delving into the GraphQL gateway, it's important to first grasp the issues associated with the REST gateway. In the example below, when we need to retrieve a book along with its author, the client must initially fetch the book and then make an additional request to obtain the author's information. Alternatively, in the case of multiple BFFs (Backend For Frontend), we would need to implement this in the API gateway. However, this would necessitate the mainten

Building a GraphQL server with Nest and Apollo

Greetings! GraphQL is rapidly gaining popularity as a more elegant solution for querying data compared to REST API. At the same time, NestJS streamlines the process of building efficient Node.js applications. In this article, I'll utilize two of them to construct a GraphQL server using NestJS. Note: I'll assume you have a basic understanding of GraphQL and NestJS. Source code -  Nest GraphQL GraphQL: A Quick Introduction GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. Schema: The GraphQL schema acts as a blueprint defining the data structure. It serves as the contract that establishes communication between the client and the server. Data Sources: These are the real data stores, which can be diverse, including databases, REST APIs, and more. Resolvers: Resolvers bridge the gap between the schema and data sources. They serve as the guides that tr