DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • Building Micro-Frontends With Vue and Reusable Components
  • Manage Microservices With Docker Compose
  • Build a Java Microservice With AuraDB Free

Trending

  • Building Scalable and Resilient Data Pipelines With Apache Airflow
  • Power BI Embedded Analytics — Part 2: Power BI Embedded Overview
  • *You* Can Shape Trend Reports: Join DZone's Software Supply Chain Security Research
  • Scalable System Design: Core Concepts for Building Reliable Software
  1. DZone
  2. Data Engineering
  3. Data
  4. Microservice Best Practices: Build an Archetype

Microservice Best Practices: Build an Archetype

In this article, we focus on learning why creating proper archetypes is important for a successful microservices architecture.

By 
Ranga Karanam user avatar
Ranga Karanam
DZone Core CORE ·
Jun. 26, 19 · Analysis
Likes (6)
Comment
Save
Tweet
Share
18.0K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we focus on learning why creating proper archetypes is important for a successful microservices architecture.

What You Will Learn

  • What is an archetype?
  • Why do you want to build microservices quickly?
  • How does an archetype help?
  • How can you use an archetype?
  • How can you build an archetype of your own?

Best Practices With Cloud and Microservices

This is the fifth article in a series of six articles on best practices with cloud and microservices. You can read the first four parts here: 

  1. The 12 Factor App: Best Practices in Cloud Native Applications and Microservices

  2. Microservices Architecture: Even Driven Approach

  3. Microservices Best Practices: Why Do You Build a Vertical Slice? 

  4. Microservices Architecture Best Practices: Messaging Queues

Why Do We Need Archetypes in Microservices?

In microservices architectures, we have a number of microservices interacting with each other. And, we keep adding microservices as we evolve.

A few questions arise:

  • How do you ensure that the microservices are consistent, i.e. similarly built and deployed? This will ensure that a developer moving from one microservice to another will not have a great deal of learning to do!
  • How do you ensure that you are able to setup a new microservice quickly?
  • How do you ensure that the new microservice is consistent with older microservices?

With microservices architectures, while the functionality of each microservice is different, you want a bit of consistency in how they are built and deployed

  • Programming language used.
  • Frameworks used.
  • The way unit tests are written.
  • Deployment and monitoring processes.
  • QA and automation testing approaches.
  • Integration with infrastructure components like Naming Server, API Gateways, etc.

This is where the reference architecture for your microservices comes into the picture. Having a good reference architecture ensures that your microservices are uniform.

How do you ensure that the reference architecture is properly implemented?

Enter Archetypes

Creating an archetype standardizes the reference architecture. An archetype is a piece of component code that can create the initial setup of a microservice, adhering to the reference architecture.

What would the output of an archetype look like?

It would consist of an example microservice with:

  • Framework integration.
  • Configuration of common external components.
  • Multiple layer setup.
  • Initial security configuration for authentication and authorization.
  • Sample automation tests for unit testing and integration testing.
  • Infrastructure setup for communication with other microservices.

Once you generate a component using the archetype, you can focus on adding business features to your microservice.

Reference Archetype Example

We have created a reference archetype for a Spring Boot microservice. The GitHub repo for the project is located here.

Using the Archetype to Create a New Project

Steps are detailed below:

Download or Clone the Github Repository

You can start with cloning the repository. Anther option is to download the repository as a zip file using this link: https://github.com/in28minutes/microservice-reference-archetype/archive/master.zip

Install the Archetype

cd to the root of the project and run the following command: 

mvn clean install

This will install the archetype to your local repository. 

[INFO] Installing /in28Minutes/git/microservice-archetype/microservice-archetype/target/project-name-archetype-0.0.2-SNAPSHOT.jar to /Users/rangaraokaranam/.m2/repository/com/organization/project/project-name-archetype/0.0.2-SNAPSHOT/project-name-archetype-0.0.2-SNAPSHOT.jar
Create a New Project Using the Archetype

Create a new folder on your hard drive. Let's call it first-project. Then execute the following commands: 

cd first-project
mvn archetype:generate -DarchetypeCatalog=local

The archetype plugin asks for a groupId and artifactId as shown below: 

Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1
Define value for property 'groupId': com.first
Define value for property 'artifactId': first-project
Define value for property 'version' 1.0-SNAPSHOT: : 
Define value for property 'package' com.first: : 
Confirm properties configuration:
groupId: com.first
artifactId: first-project
version: 1.0-SNAPSHOT
package: com.first
 Y: : Y

When the archetype plugin executes successfully, you should see the message shown below:

[INFO] Project created from Archetype in dir: /in28Minutes/git/microservice-archetype/first-project

Verify the New Project

You can do a mvn clean install command on the new project in first-project to check it everything is good.

This is a Spring Boot project with a couple of controllers and unit/integration tests.

Creating Your Own Reference Archetype

You can also create a reference archetype of your own. The first thing you need to do is to create a reference project —which would serve as the base for creating your archetype.

Setting Up a Reference Project

  • We have our reference microservice in the folder microservice-reference. This is a Spring Boot project with a couple of controllers and unit/integration tests. We use this as the reference project to reverse engineer an archetype.
  • When we create a new project using a maven archetype, the two important inputs are groupId and artifactId. In the reference project we would need to make sure that everything that needs to customized based on these inputs should be using similar values. In the microservice-reference, we use the following as the standard:
    • groupId: com.organization.project
    • artifactId: project-name
  • You would need to customize the reference-project to meet your needs or you can create a new reference-project.
  • Ensure that you configure the latest version of maven-archetype-plugin in your microservice-reference.
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-archetype-plugin</artifactId>
<version>3.0.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>

Reverse Engineering an Archetype From microservice-reference

In the command prompt, cd to the foler containing this project: 

cd microservice-reference
mvn archetype:create-from-project

You will see the following statements in the log: 

[INFO] Setting default groupId: com.organization.project
[INFO] Setting default artifactId: project-name
[INFO] Setting default version: 0.0.2-SNAPSHOT
[INFO] Setting default package: com.organization.project

An archetype project is created in microservice-reference/target/generated-sources/archetype

Copy the Created Archetype to the microservice-archetype Project

Copy the archetype project created in the above steps to the microservice-archetype folder.

Summary

In this article, we talked about the need for an archetype in a microservices architecture. An archetype serves a starting point for creating new projects and ensuring uniformity across microservices. We looked at an example archetype and got an overview of how to create an archetype.

Archetype (information science) microservice Build (game engine)

Published at DZone with permission of Ranga Karanam, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • Building Micro-Frontends With Vue and Reusable Components
  • Manage Microservices With Docker Compose
  • Build a Java Microservice With AuraDB Free

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!