Intro This is the third and last post in a series about learning gRPC, GraphQL and Kubernetes by building Microservices in Go.
Here is a list of posts in the series:
Part 1 - gRPC Microservices Part 2 - GraphQL BFF Part 3 - Deploy services by Kubernetes Full code is in here
We have implemented gRPC servers and BFF in parts 1 and 2.
In part 3, we will deploy those services using Kubernetes and Minikube.
Intro This is the second post in a series about learning gRPC, GraphQL and Kubernetes by building Microservices in Go. Here is a list of posts in the series:
Part 1 - gRPC Microservices Part 2 - GraphQL BFF Part 3 - Deploy services by Kubernetes Full code is in here
We have implemented gRPC servers in part 1.
In part 2, we will develop a BFF server that reads from and writes to these gRPC servers and communicates with clients using GraphQL.
Intro This is the first post in a series about learning gRPC, GraphQL and Kubernetes by building Microservices in Go.
In this series of posts, we will embark on a journey to implement a Backend For Frontend (BFF) and microservices architecture, leveraging gRPC and GraphQL. Additionally, we’ll demonstrate how to deploy these services locally using Kubernetes.
This project serves as an educational endeavor to understand microservices communication and the benefits of using gRPC, GraphQL, and Kubernetes.
Introduction In concurrent programming, managing tasks efficiently is crucial. One common pattern is the job queue model, where multiple tasks (jobs) are submitted to a queue and processed asynchronously by worker routines. In this blog post, we’ll explore how to implement a job queue model in Go using goroutines and channels.
Understanding the Job Queue Model At its core, the job queue model consists of two main components:
Job Queue: The job queue is a data structure that holds tasks awaiting execution.
Intro This article aims to summarize the key concepts and principles of Go’s concurrency model that I’ve learned.
To test your understanding and reinforce your knowledge, a quiz is available at the end of the article.
Goroutines A goroutine is a lightweight independently executing function with its own call stack.
While not equivalent to a thread, conceptually, it can be thought of as a very cheap thread.
Here’s how you can use goroutines:
Merge Sort In sorting n objects, merge sort has an average and worst-case performance of O(n log n).
Merge sort is a stable sort in the most implementations. The most common implementation does not sort in place, meaning it requires extra space.
Implementation in Python from typing import List # Python merge sort implementation # Time complexity: O(NlogN), space complexity: O(N) def merge_sort(nums: List[int]): # Base case if len(nums) <= 1: return nums mid = len(nums) // 2 left, right = merge_sort(nums[:mid]), merge_sort(nums[mid:]) return merge(left, right) def merge(left: List[int], right: List[int]): i, j = 0, 0 res = [] # Compare the elements in the left and right list and append the smaller one to the result list while i < len(left) and j < len(right): if left[i] <= right[j]: res.
Quick Sort In sorting n objects, quick sort has an average performance of O(n log n) and a worst performance of O(n^2).
Most implementations of quick sort are not stable, but sort in place, meaning it does not require extra space.
Implementation in Python # O(NLogN), space complexity O(n) in this case def quick_sort(nums): if len(nums) <= 1: return nums pivot = nums[len(nums) // 2] left = [n for n in nums if n < pivot] mid = [n for n in nums if n == pivot] right = [n for n in nums if n > pivot] return quick_sort(left) + mid + quick_sort(right) # Test cases if __name__ == "__main__": # Test case 1: Sorting an empty list arr1 = [] result1 = quick_sort(arr1) assert result1 == [], "Test case 1 failed" # Test case 2: Sorting a list with one element arr2 = [5] result2 = quick_sort(arr2) assert result2 == [5], "Test case 2 failed" # Test case 3: Sorting a list with multiple elements arr3 = [3, 6, 1, 8, 2, 4, 5, 7] result3 = quick_sort(arr3) assert result3 == [1, 2, 3, 4, 5, 6, 7, 8], "Test case 3 failed" # Test case 4: Sorting a list with duplicate elements arr4 = [3, 6, 1, 8, 2, 4, 5, 7, 1, 2] result4 = quick_sort(arr4) assert result4 == [1, 1, 2, 2, 3, 4, 5, 6, 7, 8], "Test case 4 failed" # Test case 5: Sorting a list with duplicate pivot elements arr5 = [3, 6, 1, 5, 4, 4, 5, 7, 1, 2] result5= quick_sort(arr5) assert result5 == [1, 1, 2, 3, 4, 4, 5, 5, 6, 7], "Test case 5 failed {0}".
Introduction Have you ever found yourself in a situation where you needed to prepare a substantial amount of data for testing your code? If so, you’re not alone. Working with large datasets is a common requirement in software development, and Go provides some powerful tools to help you accomplish this efficiently.
In this blog post, I’ll share my approach to writing a large amount of data into a CSV file using Go, and I’ll demonstrate how to leverage Goroutines to make the process more efficient and faster.
Union-Find Union-Find, aka Disjoint Set, is a rooted tree data structure that can efficiently classifies elements into categories.
By utilizing this data structure, it becomes possible to rapidly determine whether two elements belong to the same group, as well as to swiftly merge two groups.
Implementation in Python class UnionFind: def __init__(self, n): # Initialize all parents as -1, which means all nodes are root nodes self.parent = [-1] * n # Rank holds a weight to determine which tree has more weight # The tree with a smaller rank should be placed under the tree with a greater rank to keep the height of the merged tree smaller self.
Introduction This post summarizes what I have learned when I encountered issues related to CORS and HTTP cookies.
Understanding Domains(hostname), Origins, and Sites It’s crucial to comprehend these concepts when dealing with CORS-related problems.
Origin An example of a web content’s origin is http://example.com:80. An origin is comprised of the domain (hostname), port, and scheme.
In the case above, http is the scheme, example.com is the domain, and 80 is the port.