Posts

Oriented-Object Design - S.O.L.I.D

S.O.L.I.D 单一职责原则 Single Responsibility Principle 一组与同一职责紧密相关的函数和数据结构,同一个类只负责同一个职责 如:计算面积的类不打印,打印的类不计算面积 开放封闭原则 Open Close Principle 对象或者实体应该对扩展操作开放,而对修改操作封闭 如:计算面积的类,可以通过override它的function计算面积而对不同图形(实现同一图形接口的类)进行扩展 里氏替换原则 Liskov Substitution Principle(继承类有意义) 任何一个子类或者派生类应该可以替换他们的父类或基类,如果继承,那么每个继承而来的函数或者数据结构都应该有意义(不能强迫一个类继承他用不上的父类) 如:人类是父类,实现方法是颜色,吃饭,如果不同人种作为子类是符合这个原则的,因为不同人种颜色不一样,但是都有意义,也都可以吃饭;如果机器人继承人类这个父类,那么颜色make sense,但是吃饭是不行的,那么使用时这个机器人就不能替换人类这个父类,就违反了原则 接口分离原则 Interface Segregation Principle(实现接口有意义) 不能强迫一个类实现他用不上的接口 如:有一个类,是叫几何体,那么会有计算面积和计算体积的方法,如果一个长方体实现这个接口没有问题,但是如果是一个长方形实现这个接口就有问题了,因为长方形不能计算体积,或者你可以牵强的说他的体积是0,但是这并没有什么意义 依赖反转原则 Dependency Inversion Principle 抽象不应该依赖于具体的实现,相反,具体实现应该依赖于抽象,同样Hight-level的实体不应该依赖于Low-level的实体 如:在一个类A中有一个成员变量其类型为B,此时A就依赖了B,我们需要把B抽象化,抽象类或者接口即可

AWS-ECS

Image
Elastic Container Service Virtual Machine vs Containerization Advantages Environment Encapsulation In the real enterprise development environment, configuring a local development environment spends too much time and sometimes needs to spend a few days to complete that. Too many unpredictable factors are able to affect the environment configuration. Faster boot time Difference Virtual Machine Infrastructure  contains different host hardware, like CPU, RAM, Disk, Network Interface Card, etc. Host Operating System  the operating system running in the host Hypervisor  running above the host operating system also can directly communicate with the physical host, some of the hypervisors need to run in the host operating system Virtual Machine like an individual machine, each VM has its own operating system and the apps running above the VM operating system spend too much time to launch a new EC2 instance (installing an operating system...

AWS-EC2-3

Auto Scaling The purpose we need to use the auto-scaling is to dynamically scale-out the number of services to satisfied for handling the incoming traffic. Launch Configuration/Template When the auto-scaling scale-out the auto-scaling group, it will use the launch configuration or launch template to launch a new instance. Launch Configuration Configurations Instance Type AMI Key Pair Block Storage Security Group User Data IAM Role ... Launch Template Support versioning Generating template by using the currently running EC2 instance Auto Scaling Group The group which contains one or more EC2 instances, which can help to scale-out or scale-in the number of instances, but it cannot do scale-up and scale-down The auto-scaling group is existing in a  single region ,  same to ELB But it can do auto-scaling cross AZ Trying to balance the amount of the instances in different AZs by some  scenarios If launching a new instance from an AZ failed...

AWS-EC2-2

Image
AWS Load Balancer For handling the high bandwidth of HTTP request and response. Multiple servers can host the same backend service, but it is hard to be picked by the client in which the IP address of the host is the one. Additional, when no matter the auto-scaling group working or manually to scale-out or scale-in, the IP address should be added to or be deleted from the list of hosts which for hosting the service Elastic Loading Balancing responses to separate and distribute the traffic to multiple targets, like EC2, ECS, Lambda, etc.  ELB listener should be assigned at least two availability zones Each availability zone only can have one ELB node which should be assigned to a public subnet in this AZ if the traffic is public traffic, but if the traffic is coming from internal AWS instance, then the ELB node should be assigned into the private subnet in this AZ, ELB categories: Classic Load Balancer Application Load Balancer Network Load Balancer Elastic Load Bal...

AWS-EC2-1

Image
Elastic Compute Cloud (EC2) Overview Structure Generally, EC2 is consists of three parts, hardware, hypervisor, and virtual machine instances. Like the fig below. The hypervisor is kind of like a physical interface that is responsible for interacting with the physical components of the host, like Virtual Box, Hyper-V, VMware.  Each virtual machine ( EC2 instance ) communicates with physical components through its operating system which communicates with the physical components through the hypervisor. EC2 Instance "E" from "EC2" is Elastic, which means  the computing power  is able to adjust (scaling), through the auto-scaling group to implements its ( the amount of EC2 instances ) elastic scaling (scale-out or scale-in) automatically. (In short, able to adjust the amount of EC2 instances, unable to adjust the resource for the specific EC2 instance) The user has the root permission, and this is an un-managed service which means A WS doesn't kno...

AWS-VPC-2

Image
VPC Endpoints Primary Issue Some of the services and resources from AWS do not exist in VPC itself but in AWS. If there is a service from VPC needs to access the AWS services or resources, it has to pass through the public internet and then go back to AWS. This will make the cost higher and slow the speed.  Solution - VPC endpoints That is the reason why VPC endpoint here for resolving the wasting issue. Interface endpoints: PrivateLink Private link could provide a private connection through the inner AWS internet connect between AWS services or resources and VPCs (under the same or different accounts)  ENI (Elastic Network Interface) , no need to expose to the public internet. Gateway endpoints: Gateway VPC Endpoint Gateway  provides the connection between  S3  or  DynamoDB  and VPC, through the router, any service could connect VPC Endpoint Gateway with normal way. VPC Peering VPC peering  provides a connection ...

AWS-VPC-1

Image
OSI (Open System Interconnection) Model There are 7 Layers: Application Layer - http request and so on Presentation Layer Session Layer Transport Layer  - wrap data to be a  segment/datagram , there is one example in the  load balancer Network Layer - wrap data to be a  package  to transfer Data Link Layer - wrap data to be a  frame  to transfer Physical Layer - communication by using  bit  unit TCP/IP (default protocol in this course, the most famous protocol suite) Using TCP (Transmission Control Protocol) in the Transport Layer. In this layer,  UDP  also is a famous protocol we are using. Using IP (Internet Protocol) in the Network Layer., in this layer,  ICMP  also is a famous protocol we are using, which is like we are typing `ping` in cmd. IP Address `ipconfig`, check your IP information, like IP address. LAN/WAN (local area network, wide area network), the private IP address is exi...