Skip to main content

Posts

Showing posts from 2023

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

Getting Started with NestJS: A Beginner's Guide to Building Node.js Applications

Greetings! The Node.js ecosystem is undergoing rapid evolution, making it challenging to choose the right framework or library. The essential step is to build a solid foundation in basic JavaScript and Node.js concepts. But I'm curious about the newest trends in development hence trying NestJS. What is NestJS? Nest (NestJS) is a framework for building efficient, scalable Node.js server-side applications. Nest provides an out-of-the-box application architecture that allows developers and teams to create highly testable, scalable, loosely coupled, and easily maintainable applications. Why is it worth trying Nest shares similarities with Angular on the backend, drawing inspiration from Angular's concepts. For someone with a background in Java, like myself, it may feel reminiscent of working with the Spring framework. Getting started with Nest is straightforward and user-friendly. Apart from these points, there are some other aspects I'd like to emphasize. NestJS offe

Getting Started with AWS RDS

Greetings I was once tasked with setting up an earlier version of a database system for a demo. It took me a whole day to complete that task due to versioning issues in the required libraries. It was nothing but just pain. I lost valuable time as a developer that I can use for something more useful than struggling with setting up a database system. This is why cloud-based solutions are much better. AWS RDS provides us with many benefits over using traditional on-premises systems. OS upgrades and patching Automatic backups Replication High availability Security Multiple database options Hardware and networking So what is RDS? AWS RDS Amazon Relational Database Service (Amazon RDS) is a collection of managed services that makes it simple to set up, operate, and scale databases in the cloud. We can choose from seven popular engines. MySQL, MariaDB, PostgreSQL, Oracle, SQL Server, Aurora MySQL, and Aurora PostgreSQL. We can even deploy on-premises with RDS

Implementing email sending functionality with AWS SES

Greetings Emailing is a ubiquitous feature in modern applications that requires a reliable service to meet our email needs. Luckily, AWS Simple Email Service (SES) offers a cost-effective and secure solution. AWS Simple Email Service AWS SES is an email solution that relieves us of all operational responsibilities. It is an email platform that offers a convenient and affordable method for sending and receiving emails using your own email addresses and domains. Can I do "that"? When considering the use of such a service, we typically contemplate these functionalities. Personally, I experienced these aspects when incorporating AWS SES into our recent email feature. Sending simple emails Sending fancy HTML emails Send emails in bulk Send dynamic emails Store template somewhere Use list Use conditions Send attachments Send to multiple recipients Absolutely! SES indeed supports all of these features. Moreover, it can also be utilized for automatic

Effective Strategies for Handling External Services

Greetings In various software development scenarios, we inevitably encounter external dependencies, whether they are our own services or entirely third-party entities. Especially when it comes to microservices this is very common. Systems can fail or crash if we don’t plan and handle these scenarios properly. Having personally encountered such situations, I became increasingly curious to delve deeper into this. Note that there are no “exact” answers when comes to these kinds of situations. The best is to let the business decide which option to use as it will save a lot of time, engineering effort and of course money by not over-engineering. What can go wrong? Let's first categorize the scenarios that can happen when using external systems. Service Unavailable Service is not able to handle high load Service had implemented rate limits Service is slow All these will impact our businesses hence we need to carefully design our systems. However, we cannot say there is a perfect solution

Design a serverless web scrapper

Greetings In a previous article , I explained how we synced the WordPress website into our microservices architecture. We use AWS EKS for our deployments and managing microservices. But what if we use a serverless architecture? Here is my attempt at the serverless solution on my serverless journey. Note that this is about converting your own website into a serverless architecture. Always check ethicality in use. Note: This is about the architecture, not about actual coding. Requirement Convert existing website into a serverless microservice. Technologies By sticking into Nodejs and AWS I would go with the below stack. AWS Lambda AWS S3 AWS Eventbridge AWS RDS AWS API gateway AWS Cognito AWS CloudFront AWS Amplify AWS SES Nodejs JavaScript Axios Cheerio React I would consider AWS Step functions in the future as one lambda is doing too many things (save in database, store images in S3, send emails). However, my AWS Step functions knowledge is not as great as today. Architecture Let's

Redis Cache with Nodejs, AWS

Greetings Modern applications are highly data-driven, and distributed and performance is a top priority. Redis has become one of those critical components in most applications. In this article, we will briefly look into Redis and how we can use it in a NodeJS application. "Power real-time applications with sub-millisecond latency" Redis Fast, open source in-memory, a key-value data store for use as a database, cache, message broker, and queue (from the doc). It stands for Remote Dictionary Server. We usually think of Redis as a cache because it is the most used use case. But Redis is more than a cache. As an example, Redis is an ideal option to store user sessions in web applications. Here are a few use cases but for more details better to read the documentation. Caching Session store Messaging Queue Gaming leader boards Geospatial Caching is a must in Microservices architecture to improve performance. We utilize Redis for this purpose in our e-commerce ap