Microservice Mastery: 3 Crucial Factors to Consider Before You Start Building — Part 2

Andreas Loizou
3 min readApr 28, 2023

Welcome back to our Microservice Mastery series! In part 2, we continue exploring the crucial factors you need to consider before building your microservices. If you missed part 1, you can find it here. Now, let’s dive into best practices and must-have tools for monitoring, analytics, and logging!

Are you building microservices? What are some best practices that you could use? There is a zillion of them, but let’s cover some of the must-do ones here!

Monitoring and Analytics

A robust monitoring solution is non-negotiable! You need a tool that efficiently manages your logs, Kubernetes, pods, infrastructure, and dashboards. While there are countless monitoring and analytics tools available, it’s vital to choose one that caters to your specific use case and integrates seamlessly with your other tools. Keep scalability, security, and integration in mind while selecting the right tools for your needs. To help you get started, here are some popular options:

  • Log Monitoring — e.g. ELK stack, Graylog, Datadog.
  • Service Monitoring: Skooner (shows the number of instances and connects to corresponding Docker containers)
  • Monitoring of our infrastructure and dashboards — Prometheus, Graphana

Logging

Effective logging is crucial for troubleshooting and debugging microservices. Your application should always have:

  • Application Logs
  • Access Logs (where applicable)

Take time to plan your logging strategy, ensuring log entries provide valuable insights to assist in troubleshooting. But that’s not all — consider structured logging for even more benefits.

Structured Logging

  1. You may be familiar with traditional log entries like this:
2651: [22/02/2023 15:27:34.650] 10.123.151.34 — — “POST /subscribe.htm HTTP/1.1” 500 3819 “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.50”

While this format is human-readable, software tools should monitor log entries for maximum productivity. With structured logging, log entries are formatted in a machine-readable manner, such as JSON:

{
"source": "my-microservice",
"timestamp": "2023-02-22T15:27:34,650Z"
"resp_body_size": 23615,
"host": "api.example.com",
"address": "10.123.151.34",
"request_length": 482,
"method": "POST",
"uri": "/subscribe",
"status": 200,
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.50",
"resp_time": 0.042,
}

Structured logging enhances debugging and troubleshooting, making log searching and analysis more manageable and efficient. For instance, monitoring tools like Elastic allow you to search through logs using various parameters, leading to quicker issue identification.

In addition to structured logging, consider centralized logging solutions like ELK or Splunk to aggregate logs across multiple microservices and gain insights into your system’s overall performance.

Conclusion

Mastering microservices involves a deep understanding of monitoring, analytics, and logging best practices. By implementing robust tools and strategies, you can ensure the smooth functioning and maintainability of your microservices architecture.

There’s more way to go!

Well done, friend💪! You are great. You’ve just finished the second part with another 3 essential points you should consider when creating microservices.

So, stay tuned for more blog posts, courses and videos!

I invite you to share your experiences and best practices in the comments section.

Don’t forget to follow me on Twitter, where I share more information regarding best practices when you design, develop, deliver and maintain software!

--

--

Andreas Loizou

Software Engineering Trainer | Director of Engineering @ https://www.qbeat.io | @UniofOxford alum. No limits. Dares the Unknown