Piral Feed Service 1.10
Tags: webdev, javascript, piral, microfrontends
Published: 2023-04-03 09:21:47

The Piral Feed Service is a commercially available [micro frontend discovery service](https://dev.to/florianrappl/micro-frontend-discovery-the-driver-for-scalability-oai) with a free tier that works for many solutions such as Webpack Module Federation, single-spa, Native Federation, OpenComponents, or Piral.

With the release 1.10 the Piral Feed Service adds some new powerful features that make it even more attractive for new teams - giving them some interesting capabilities such as standalone feature flags out of the box.

In this post we'll walk over some of the highlights of this release and how these features can impact your work.

## Micro Frontend Infos

Previously, the Piral Feed Service only showed some information of a micro frontend such as the used version or the name of the micro frontend.

![Micro frontend overview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sqajpa4x6p67i94nf6v5.png)

With the arrow icon on the right hand side you can now show additional information.

![Additional information on the micro frontend](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9k3x5xl2egtruiuij9l3.png)

This is great to see what's the size of the micro frontend, how it's structured and what dependencies are there (and if they are shared).

In case of an uploaded `README.md` file you even get to see some documentation of the micro frontend:

![README of the micro frontend](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ttnbgydth99bw0er806i.png)

This aligns quite well with previously available views such as the dependency view, which is available since quite a while:

![Dependency view within the Piral Feed Service](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v73p2ryc1p1w4t57e60h.png)

All in all, it is now possible to inspect the published micro frontends even better - yielding all kinds of useful information.

## Feature Flags

Many of our customers told us that the included feature flag / rule evaluation from the Piral Feed Service is more powerful and works even better than dedicated feature flag services such as LaunchDarkly, Split, or Azure Configuration. What was missing is a way to have dedicated or standalone feature flags, which are independent of micro frontends and could be used within micro frontends, or some other application.

This is now possible. Every feed has a new action item called "Manage Feature Flags".

![Manage Feature Flags](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p14ht5zje65o2vv8o42m.png)

Following this action you can create new feature flags using an identifier and description.

Once created the feature flags are available - and can also be fully toggled:

![Available feature flags](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mc7hx7czpnymzcmcon7j.png)

There is a dedicated URL to retrieve the available feature flags. Following the `/api/v1/feature/{feed}` URL you'd get a response that includes the `flags` property:

```json
{
  "feed": "example",
  "flags": ["feature1", "feature2"]
}
```

Only the enabled features for the given request are listed.

For instance, if you have a rule for a feature "my-feature" like the following:

```json
{
  "type": "query",
  "name": "access",
  "compare": {
    "type": "eq",
    "value": "456"
  }
}
```

then the flag would show only if `/api/v1/feature/example?access=456` is requested:

```json
{
  "feed": "example",
  "flags": ["my-feature"]
}
```

But not otherwise (e.g., `/api/v1/feature/example?access=123`):

```json
{
  "feed": "example",
  "flags": []
}
```

The best thing about feature flags is that they are also a way to re-use rules across multiple micro frontends. Let's say you want to re-use the rules for `my-feature` above in two micro frontends, you can just create a single rule for each micro frontend:

```json
{
  "type": "feature",
  "name": "my-feature"
}
```

This way, you can easily make feature flags your primary mechanism for toggling micro frontends, without having to duplicate their rules.

## Publish Overrides

One thing that the Piral Feed Service implemented from the beginning is protection against version conflicts. As such it prevented publishing one micro frontend again using the same version.

While this is great and enables a lot of optimizations (e.g., micro frontends are ensured to be immutable and therefore can be cached indefinitely) it also comes with convenience drawbacks. To mitigate this a special "preview" property has been added to the *package.json*. If a micro frontend has

```json
{
  "name": "my-mf",
  "version": "1.0.0",
  "preview": true
}
```

then the Piral Feed Service would always append a special preview suffix (e.g., making the version `1.0.0-pre.1234`). The downside of this approach was that the property is part of the *package.json* and therefore not something that is easily enforceable, e.g., just for a certain branch or publish action.

Now, the Piral Feed Service supports various overrides such as `version` or `preview`:

```sh
# change the version to be a preview
npx publish-microfrontend --url ... --interactive --fields.preview on

# change the version to be 1.2.3
npx publish-microfrontend --url ... --interactive --fields.version 1.2.3
```

While the first call overrides the `preview` flag of the *package.json* (i.e., it does no longer require that or changes its value if that property exists), the second changes the provided `version`. Both overrides also work together.

## Additional Rules

As mentioned, the rule engine provided by the Piral Feed Service is definitely a powerful one - and features many possibilities that make dynamic rule evaluation and feature management convenient and flexible.

One thing that was wished here was time-based evaluation. While this could be introduced via custom rules, we thought that this is a great generic addition that should not be missed here.

There are three new rule types here (`not_before`, `not_after`, and `cronjob`). The first two are also available in a new wizard:

![Wizard for not before or after rules](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8hq6vcomuktwz4g41930.png)

If you follow the wizard you'll get the option to define a time window using a not before / not after date. The times are always given in UTC.

![Wizard for the time window](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7o65md2j9e3ha4amgty.png)

Using this you can easily either make your micro frontends expire (e.g., for a given deal you want to show some preview here, but once the deal is off the table you want to also hide the content of the micro frontend) or just go online at a certain point in time (your big rollout is on Monday 6am, but no developer will be available - just make sure to have everyone publish their micro frontend beforehand and set the rule to make the micro frontend available at Monday 6am).

In contrast, using cronjob is for re-occurring rules, i.e., when your micro frontend should only available on Sundays or during office hours.

For instance, the following rule will activate a micro frontend at 9am UTC for 3 hours every day:

```json
{
  "type": "cronjob",
  "duration": 180,
  "hour": 9,
  "minute": 0
}
```

If the `duration` is skipped then it will match the whole day after the time is met.

## Conclusion

The Piral Feed Service is the most powerful micro frontend discovery service. The free [community edition](https://portal.piral.cloud/) is great to get started. To try the service in your environment you can either [go the Azure Marketplace](https://portal.azure.com/#create/hub) to obtain Azure Container Registry access or [contact us](https://www.piral.cloud) to start a free trial of the full service.