關於網路那些事...

Marketing, SEO, Web trends, Programming tutorial, Web design, and Life event...

Choosing Between LEFT JOIN and Foreign Key in MySQL: Flexibility and Performance Considerations

In MySQL, both LEFT JOIN and FOREIGN KEY serve different purposes and come with their own advantages and disadvantages.

The decision on which to use depends on your needs regarding flexibility, data integrity, and performance. Let’s break down each approach:

Continue Reading

MySQL JSON and Relation Tables Performance Optimization

When developing and optimizing MySQL databases, we often face the choice of using JSON fields or relational tables to manage data. This article will explore performance optimization methods for using JSON fields and relational tables in MySQL.

The advantages of JSON fields are compact data structure, reduced number of tables, and fewer join operations. However, parsing JSON fields incurs significant overhead, has limited index support, and may have lower query efficiency on large datasets.

The advantages of relational tables are clear relationship models, comprehensive index support, and efficient query optimization. However, it requires additional tables and join operations, which are typically efficient in relational databases.

In scenarios with millions and tens of millions of users, what are the advantages and disadvantages of these two approaches in terms of efficient querying and flexibility? Here are the considerations:

Scenario: A membership system that allows members to create organizations and share them with other members. In the struct of Organization, Permissions are used to record member IDs and roles. Under the organization, the ability to add courses and units while allowing member sharing at different levels needs to be maintained.

Continue Reading

Casbin Model - What is PERM and Example

Casbin is an authorization library that supports access control models like ACL, RBAC, ABAC for muti-language.

Before developing Casbin, it is necessary to understand the underlying basic model and how to configure a permission management model that suits your needs.

First, the casbin model are base on PERM (Policy, Request, Effect, Matchers) with following settings:

  • sub (subject): The entity accessing the resource, such as a member, user, or device. It represents who is making the request.
  • obj (object): The resource being requested, such as a feature, page, or folder. It represents what is being requested.
  • act (action): The method or behavior of the request, such as publish, edit, view, disable, etc. It represents how the request is made.
  • eft (effect): The result of the policy after defining the sub, obj, and act. It can be set as true, false, or null (indicating allow).

And further, it can be combined with roles to manage roles or multi-tenancy.

Next, we will explain the Casbin model. During the learning process, you can practice and operate in the Casbin official editor.

Continue Reading

Golang: Use viper with local config, management with struct, and envrionment variables

Viper is a complete configuration solution for Go applications. It is designed to work within an application, and can handle all types of configuration needs and formats. Also, viper has many features, such as support for different configuration formats (JSON, TOML, YAML, etc.), live watching and re-reading of config files, reading from environment variables, etc.

Here will demostract how to use viper with local config, management with struct, and envrionment variables.

Continue Reading

Golang Design Pattern Singleton (GORM as example)

Singleton Design Pattern

The Singleton pattern is a creational design pattern that ensures a class has only one instance and provides a global access point to it.

In software development, there are situations where we need to restrict the instantiation of a class to a single object. This is particularly useful when dealing with shared resources or managing global state.

The Singleton pattern is implemented by defining a class with a private constructor and a static method. The first time the static method is called, it creates a new instance of the class. In subsequent calls, it returns the existing instance.

The Singleton pattern provides the following benefits:

  • Ensures that there is only one instance of a class in the application.
  • Provides a global access point to that instance.
  • Delays the initialization of the instance, improving performance and resource utilization.

The following are two implementations of the Singleton pattern in Go, each demonstrating how to connect to a database:

Continue Reading

How to Correctly Update Your Golang Project Version

Before upgrading Go to specific version, you need to upgrade the environment. Next refer to the following sections to upgrade Go version:

Upgrade the Go version in go.mod

The go.mod file specifices the Go version used in project.

Find the current Go version on the file line of go.mod file. For example, if the version is 1.19, change to 1.22 (or whatever version you want to upgrade to). This step is curcial as it tells Go to compile your project with the specified version.

go 1.22

Continue Reading

Asdf Introduction & Quick Guide

asdf is a versatile version manager designed to simplify the management of multiple runtime versions, such as programming languages, tools, and frameworks, within a single development environment. With asdf, users can easily install, manage, and switch between different versions of various software packages, ensuring compatibility and flexibility across projects. Whether you’re a developer, system administrator, or anyone who needs to juggle multiple versions of tools, asdf provides a seamless solution, enhancing productivity and eliminating version-related headaches.

Continue Reading

Video Streaming Encoding profile

流媒體編碼(Streaming encoding)是將音頻或視頻數據轉換為壓縮格式,以便通過互聯網或其他數據通信通道進行即時傳輸的過程。這一過程需要將原始的音頻或視頻數據轉換為更小的數據流,同時保持足夠的質量,以確保觀眾能夠在即時播放的同時獲得良好的觀看體驗,以下將針對影片編碼原理及知識作介紹:

流媒體協議(Streaming Protocol)

流媒體協議(Streaming Protocol)是一種用於在網路上傳輸音訊和視訊的通訊協定。這些協定通常被用於實現即時傳輸,允許用戶在資料流正在下載的同時開始觀看或聆聽內容,而無需等待整個檔案完全下載。

以下是一些常見的流媒體協定:

Continue Reading

How to Get Real Client Ip on Cloudfront

How to get real client IP in AWS CloudFront

In the realm of web development, obtaining accurate client IP information is a common challenge, especially when leveraging Content Delivery Networks (CDNs) like AWS CloudFront. The quest for the client’s true IP address often involves navigating through headers like X-Forwarded-For, but it’s not as straightforward as it might seem.

Continue Reading

An Introduction to Kubernetes (1) Environment Preparation

Containerization has revolutionized the way applications are deployed, offering increased portability and scalability. At the forefront of container management, Kubernetes has emerged as a dominant open-source platform.

Derived from the Greek word for helmsman or pilot, Kubernetes aptly serves as a pilot, skillfully managing workloads while you set the course for your applications.

In kubernetes series article, we will explore Kubernetes' essential features, its role in managing containerized workloads, and its extensibility options, empowering developers to harness its full potential.

In this section, will introduction about environment preparation in linux and Mac.

Continue Reading

An Introduction to Kubernetes (2) Cluster Introduction

Kubernetes is an open-source container orchestration platform that automates the deployment, scaling, and management of containerized applications. It was originally developed by Google and is now maintained by the Cloud Native Computing Foundation (CNCF). Kubernetes provides a robust and scalable infrastructure to manage and deploy containerized applications in a consistent and efficient manner.

In kubernetes series article, we will explore Kubernetes' essential features, its role in managing containerized workloads, and its extensibility options, empowering developers to harness its full potential.

A Kubernetes cluster is a set of physical or virtual machines (nodes) that are connected together to form a cluster. The cluster is managed by the Kubernetes control plane, which includes several components responsible for maintaining the desired state of the cluster. These components ensure that applications are running as intended and handle tasks such as scaling, load balancing, and monitoring.

Node with following components:

Continue Reading

An Introduction to Kubernetes (3) Publish Application to Amazon Elastic Kubernetes Service

Kubernetes has become the standard for container orchestration, enabling developers and DevOps teams to manage containerized applications efficiently and securely. It has a vibrant ecosystem and a vast community that continues to drive innovation and adoption of cloud-native technologies.

In kubernetes series article, we will explore Kubernetes' essential features, its role in managing containerized workloads, and its extensibility options, empowering developers to harness its full potential.

Before we introduction the environment preparation and cluster. Here will introduction the key concepts in kubernetes:

Continue Reading

An Introduction to Kubernetes (4) Troubleshooting & References

In kubernetes series article, we will explore Kubernetes' essential features, its role in managing containerized workloads, and its extensibility options, empowering developers to harness its full potential. An Introduction to Kubernetes (1) Environment Preparation

Continue Reading

Use Python to build a automatic scheduling process for OpenID login facebook and interactions with website

Recently, have had some scheduling tasks that need to execute on the website. This will cause high effort for this manually routine job.

For reducing the effort, I build an automation mechanism to replace the routine job, here will record the process for anyone who needs refer.

This article will use an example as a case to demonstrate how to build this automation process, and the following are this example of system processing:

Continue Reading

Why event-driven architecture is a good choice for aggregating two applications

What is an event-driven architecture?

Traditional approaches to integrating applications involve tightly coupling them together, making changes to one system impact the other.

Event-driven architecture is an excellent way to decouples and aggregate two or more applications because it provides a flexible and scalable way to integrate and communicate between different systems sources, such as user actions, system events, or sensor data. Event-driven architectures are used to build complex and scalable systems that respond to changes in real-time.

Continue Reading

Introduction data lake and how to establish on AWS

A data lake is a centralized repository for storing and managing large amounts of raw data in various formats. Amazon Web Services (AWS) provides a comprehensive range of services that can be used to set up a data lake system. In this article, we will introduct how establish a data lake on AWS.

Continue Reading

How to grant Cross AWS Account Access Resource by resource-based policies in microservices

Recently, our payment service is building with serverless Event-Driven Architecture with SNS, SQS, and lambda function, this will support the Event callback with core payment event service (the following will show as core event service), and this core event service are integration muli-purchase 3rd vendor to one interface.

When a user has subscriptions behavior in our platform, each action send to 3rd party vendor, the 3rd party vendor will create an Event to core event service, and the core event service send the callbacks Event to project payment service’s SNS, for the final process, project service need provide a cross VPC account access SNS grants to core Event service:

3rd vendor --(callback event)--> core event service --(callback event)--> project

Continue Reading

How Manage Aws Ecs Sensitive/Non-Sensitive Environment Variables

When developing an APP in ECS, We need to pass the environment variables to the tasks container.

Because we have sensitive and non-sensitive environment variables, so we need to take care in choosing the policy.

Continue Reading

Troubleshoot on AWS Elb Return 5xxs Error: 504 Gateway Timeout

We have a service that sometimes got a 504 Gateway Time-Out response from ELB( actually is CLB).

When investigating the root cause, we found out that CLB’s 3 instances are normal in the current two weeks, and the 504 time-outs happened in CLB.

Continue Reading

What different key features between Http1 Http2 Http3?

In this article, we will introduce the main key features of HTTP 1.0, HTTP 1.1, HTTP 2.0, and HTTP 3.0.

HTTP1.0

HTTP1.0 was published in 1996 and already obsoleted.

In HTTP1.0, each request needs to make TCP 3-way-handshake connection, which means will high cost for time-consuming and low efficiency.

Continue Reading