Craft your Nano-Service

Craft your Nano-Service

This year, I got a chance to architect a high performing API services for one of our flagship product development.?

Initially I wanted to build it as a micro-services.? But, I actually built it as a nano-service; a service has only one functional endpoint.? As a result, you will have more number of services but you will get an opportunity to fine-tune each services in its own way.?

It is similar to your Lambda/Azure Function function, if you will, but it will run in your own container on your preferred host.

?Typically this kind of architecture has 3 classes of services.

  1. Front-ending, public facing API (Offers Gateway services to your services like Auth, input validation, metering etc.)
  2. Core Services, which does the business logics and any external interactions
  3. Ancillary services which does cross-cutting functionalities. (logging, auth, etc.)

?All these services have their own settings for scaling, resource allocations security boundaries

?

Below are the key design guidelines

  1. Define the application scope to perform only one atomic functionality. This is not ideal for all kinds of services. But can be possible for backend services, if you carefully design.
  2. Use lightweight container images and measure the start-up time in your local environment itself.? Make sure they take only few milli-seconds to startup. (<50 milliseconds)
  3. Enable auto-scaling and set up scaling triggers individually for each components.? set triggering metrics carefully to raise alarms.
  4. Don't scale for just 1 peak.? For example, Check for 5 intervals at least to decide.? e.g. for a period of 3 minutes, poll every 30 seconds.? If there are 4/6 peaks, then scale up.? It indicates that there is a stress.
  5. Always go for least number of resources.? 0.25 V-Core? and 1 GB RAM, if possible.? In most cases, it will do well if you designed your nano-services as a small one.
  6. Setup health-checks appropriately and not overwhelming.?
  7. Wherever possible, use event based architecture to process asynchronously. e.g. login audit, transaction logs, execution logs.? These are first sent to a queue and processed by a processor at its own pace.?? This will improve the response time of the service.
  8. For high performance service, use cache and design cache keys appropriately.
  9. more importantly, Carefully design the name of the service to predict the class by its name itself.

Below are some of the development guidelines that you can follow for creating nano-services.

  1. Develop in local machine with the container images. Almost all services/DBs provides containerized images.
  2. Test all your code with dependent images setup in local itself before move it to your target hosted environment.
  3. Deploy the services in the container images in your cloud host Dev environment (e.g. AWS/ECS) . You should have CI/CD.
  4. Have your test collection ready (e.g. in postman) and execute it in local? as well as in your Dev environment.? Add test scripts in your collection itself so that it verifies every time you run and it save lot of time.
  5. Use Mock services extensively for all combinations to test with external services without hitting the actual targets.? This will help you to test your services predictably in all possible scenarios.? Postman Mock server is really a great service to mock up your scenarios.
  6. Do the load/performance testing in your Dev environment itself. In such nano-services applications all environments are equal in terms of capacity, exception to PROD environment. Do multiple rounds of loads to verify your scale-up/scale-down works perfectly.
  7. Terraform it so that the same set-up is applied in all environments.
  8. Assess the execution metrics, cache efficiency, DB reads etc. during the dev phase and tune your algorithm and resources accordingly.

Summary

Custom built Nano-services on a container, which mimics Lambda/Azure Functions, offers flexibility and provides lot of room for performance tuning, scaling and cost optimization. With proper instrumentation setup, it would be very fast to develop and easy to maintain/enhance. If you create a template of the service, it is just a matter of adding your code implementing the functionality.

Let me know what you think.

Reeshabh Choudhary

Student. Software Architect. Author : Objects, Data & AI; Concurrency & Parallelism. Interested in History & Sports.

4 个月

Kubeflow uses this concept to orchestrate ML pipelines.

要查看或添加评论,请登录

Mahadevan Hariharan的更多文章

社区洞察

其他会员也浏览了