In this section, we are going to review most asked interview questions on micro-services architecture as well as micro-services in java.
1. What is an API gateway?
A. An API gateway or a service gateway is a software mechanism that sits between a client and a collection of back-end services.It provides single entry point in to the system. It is mainly responsible for request routing and security.
An API gateway acts as a reverse proxy to accept all API calls, aggregate the various services required to fulfill them, and return the appropriate result.
2. How to upload images to a web service?
A. We can upload image in a web service by marking the endpoint method with @consumes(media.type= MULTI_PART_FORM_DATA)
3.What is a loadbalancer?
A. Load balancing refers to efficiently distributing incoming network traffic across a group of back-end servers such that it maximizes speed and CPU utilization and ensures that no one server is overworked, which could degrade performance.
4. Explain ELK stack and how it is used in micro-service architecture?
A. "ELK" is the acronym for three open source projects: Elasticsearch, Log-stash, and Kibana. Elasticsearch is a search and analytics engine. Log-stash is a server‑side data processing pipeline that ingests data from multiple sources simultaneously, transforms it, and then sends it to a "stash" like Elasticsearch. Kibana lets users visualize data with charts and graphs in Elasticsearch.
In micro-services ELK stack can be used for various use cases the most common being to aggregate central store for logs created by micro-services.
These three projects are used together for log analysis in various environments.
So Log-stash collects and parses logs, Elastic search indexes and store this information while Kibana provides
a UI layer that provide actionable insights.
The Elastic Stack is the next evolution of the ELK Stack.(- WWW.elastic.co)
5. How do you manage security in a micro-services application?
A.
a. Enable rate limiting on API gateway - API gateway provides single entry point in to the system and therefore responsible for the request routing and security. Rate limiting protects your API against DoS attacks, which can tank a server with unlimited HTTP requests.
b. Generate and propagate certificates dynamically - We should use SSL certificates for communication between micro-services. The certificates should be renewed or refreshed frequently to ensure security. All these steps should be managed dynamically using tools that are able to address this. HashiCorp's Vault is one such tool.
c. Use SSL in micro-services communication - Using SSL for external facing micro-services is obvious but we should also secure the services handing sensitive data with SSL. It is good practice to secure configuration server with SSL.
d. Keep configuration data encrypted - We should atlest encrypt the sensitive data like passwords. This is inbuilt in to Spring cloud config server.
e. Restrict access to API resources - Implement authorization using OAuth 2.0 or similar mechanism. OAuth 2.0 is the industry-standard protocol for authorization.
f. Dynamically generate credentials for external systems - Our system will need to connect to some external resource like a data base or a message broker. The credentials that we need to connect to these systems must be generated dynamically using Vault by HashiCorp or similar such tools.
g. Always be up to date - Ensure your libraries are updated to latest versions. Dependency scanner tools like owasp or synk can be used to handle this.
6. What are advantages and disadvantages of micro-services?
A.
Advantages of Micro-services
- Micro-services are self-contained, independent deployment modules.
- They are scalable as compared to monolithic architecture.
- Micro-services are independently manageable services therefore adding new services does not affect existing services.
- Changes are limited to specific services which reduces impact on overall application.
- Micro-services allows us to choose technology best suited for the job.
- Micro-services enable better enforcement of the single responsibility principle.
- The demanding service can be deployed on multiple servers to enhance performance.
- Less dependency and easy to test.
- Dynamic scaling.
- Faster release cycle.
- Suitable for highly scalable applications.
Disadvantages of Micro-services
- Micro-services has all the associated complexities of the distributed system.
- There is a higher chance of failure during communication between different services.
- Difficult to manage a large number of services.
- Problem, such as network latency and load balancing need to be addressed.
- Complex testing over a distributed environment.
- Not suitable for stable systems with no major scaling needs or changes.
7. What are mono-repo and multi-repo micro-services applications?
A. Micro-services are independent deployment modules. There is no need to keep them on different repositories. Alternatively using separate repositories is also possible. This gives rise to 2 ways for maintaining microservices applications in a source control.
a. Mono-repo - Where all micro-services which constitute an application reside in same repositories.
b. Multi-repo - In this arrangement micro-services reside in separate repositories and altogether do not share any common space.
Either approach has similar pros and cons and it is purely a matter of convenience for the developers to choose one approach.
8. Which container do you use to deploy your micro-services?
A. Docker is most common container to deploy micro-services. Kubernetes is a popular container management tool used to manage docker containers.
9. How to ensure availability and fault tolerance in a micro-services application?
A. Availability means the uptime of an application, when requested. An application must always be available to its users. Availability is measured as ratio of uptime to total time the system was in use.
Fault tolerance refers to the ability of system to recover from a failure, without affecting availability.
A fault tolerant system continues to function normally even as a failure is happening or has already happened. Exception handling is an example to fault tolerance.
10. How can we keep track of large number of micro-services in an application?
A. Following practices helps manage large number of micro-services efficiently:
a. Keep it simple - Micro-services are supposed to be loosely coupled and do just one thing well.
b. Develop best practices for devops and security
c. Implement logging and monitoring solutions for micro-services containers
d. Use container management tools to gain visibility across cloud and non-cloud end points
e. Ensure that each containerized micro-service adheres to a “minimum set of operational capabilities” so that it works well within such an environment.
f. Practice blameless postmortems regularly to learn and improve.
g. Implement CI/CD
h. Continuously revisit ans re-invest in your operations.
Comments
Post a Comment