No More Spaghetti Flows
Tags: 2020, apachenifi, apachenifi110
Published: 2020-06-09 20:29:48

---
title: No More Spaghetti Flows
published: true
date: 2020-06-08 15:50:00 UTC
tags: 2020,apachenifi,apachenifi,apachenifi110
canonical_url: 
---

Spaghetti Flows

  

![](https://lh6.googleusercontent.com/ylV7HM0-NbJdv1Sml3kvRVw8t8B0YNJjGr5qdnfrJM86kSPOZhoBL3MovTUUofw747U3TzrzEfT4eKoHhXQqIS4VSKcaKaa6xu0eRUKzYej0ftVrm8ODaup292tiA0DU9IpM47Zf)

  
  

You may have heard of:   [https://en.wikipedia.org/wiki/Spaghetti\_code](https://en.wikipedia.org/wiki/Spaghetti_code).   For Apache NiFi, I have seen some (and have done some of them in the past), I call them Spaghetti Flows.

  

Let's avoid them.   When you are first building a flow it often meanders and has lots of extra steps and extra UpdateAttributes and random routes. This applies if you are running on-premise, in CDP or in other stateful NiFi clusters (or single nodes). The following video from Mark Payne is a must watch before you write any NiFi flows.

  

Apache NiFi Anti-Patterns with Mark Payne

  

[https://www.youtube.com/watch?v=RjWstt7nRVY](https://www.youtube.com/watch?v=RjWstt7nRVY)

  

Do Not:

- Do not Put 1,000 Flows on one workspace.

- If your flow has hundreds of steps, this is a Flow Smell.   Investigate why.

- Do not Use ExecuteProcess, ExecuteScripts or a lot of Groovy scripts as a default, look for existing processors

- Do not Use Random Custom Processors you find that have no documentation or are unknown.

- Do not forget to upgrade, if you are running anything before Apache NiFi 1.10, upgrade now!

- Do not run on default 512M RAM.

- Do not run one node and think you have a highly available cluster.

- Do not split a file with millions of records to individual records in one shot without checking available space/memory and back pressure.

- Use Split processors only as an absolute last resort. Many processors are designed to work on FlowFiles that contain many records or many lines of text. Keeping the FlowFiles together instead of splitting them apart can often yield performance that is improved by 1-2 orders of magnitude.

  

Do:

- Reduce, Reuse, Recycle.    Use Parameters to reuse common modules.

- Put flows, reusable chunks (write to Slack, Database, Kafka) into separate Process Groups.

- Write custom processors if you need new or specialized features

- Use Cloudera supported NiFi Processors

- Use RecordProcessors everywhere

- Read the Docs!

- Use the NiFi Registry for version control.

- Use NiFi CLI and DevOps for Migrations.

- Run a CDP NiFi Datahub or CFM managed 3 or more node cluster.

- Walk through your flow and make sure you understand every step and it’s easy to read and follow.   Is every processor used?   Are there dead ends?

- Do run Zookeeper on different nodes from Apache NiFi.

- For Cloud Hosted Apache NiFi - go with the "high cpu" instances, such as 8 cores, 7 GB ram.

- same flow 'templatized' and deployed many many times with different params in the same instance

- Use routing based on content and attributes to allow one flow to handle multiple nearly identical flows is better than deploying the same flow many times with tweaks to parameters in same cluster.

- Use the correct driver for your database.   There's usually a couple different JDBC drivers.

- Make sure you match your Hive version to the NiFi processor for it.   There are ones out there for Hive 1 and Hive 3!   HiveStreaming needs Hive3 with ACID, ORC.  [https://community.cloudera.com/t5/Support-Questions/how-to-use-puthivestreaming/td-p/108430](https://community.cloudera.com/t5/Support-Questions/how-to-use-puthivestreaming/td-p/108430)

  

Let's revisit some Best Practices:

  

[https://medium.com/@abdelkrim.hadjidj/best-practices-for-using-apache-nifi-in-real-world-projects-3-takeaways-1fe6912101db](https://medium.com/@abdelkrim.hadjidj/best-practices-for-using-apache-nifi-in-real-world-projects-3-takeaways-1fe6912101db)

  

Get your [Apache NiFi for Dummies.](https://www.cloudera.com/campaign/apache-nifi-for-dummies.html?utm_source=tim)   My own [NiFi 101](https://www.datainmotion.dev/2019/03/apache-nifi-101.html).

  

Here are a few things you should have read and tried before building your first Apache NiFi flow:

- [https://nifi.apache.org/docs/nifi-docs/html/nifi-in-depth.html](https://nifi.apache.org/docs/nifi-docs/html/nifi-in-depth.html)

- [https://pierrevillard.com/best-of-nifi/](https://pierrevillard.com/best-of-nifi/)

- [https://blogs.apache.org/nifi/](https://blogs.apache.org/nifi/)

- [https://www.freecodecamp.org/news/nifi-surf-on-your-dataflow-4f3343c50aa2/](https://www.freecodecamp.org/news/nifi-surf-on-your-dataflow-4f3343c50aa2/)

- [https://www.nifi.rocks/documents/nifi-expression-language-cheat-sheet.pdf](https://www.nifi.rocks/documents/nifi-expression-language-cheat-sheet.pdf)

Also when in doubt, use Records!  Use Record Processors and use pre-defined schemas, this will be easier to develop, cleaner and more performant. Easier, Faster, Better!!!

  

There are record processors for Logs (Grok), JSON, AVRO, XML, CSV, Parquet and more.

  

Look for a processor that has “ **Record** ” in the name like PutDatabaseRecord or QueryRecord.

  

Use the best DevOps processes, testing and tools.

- [https://www.datainmotion.dev/2019/11/nifi-toolkit-cli-for-nifi-110.html](https://dev.to/tspannhw/nifi-toolkit-cli-for-nifi-1-10-213h)

- [https://pierrevillard.com/2018/04/09/automate-workflow-deployment-in-apache-nifi-with-the-nifi-registry/](https://pierrevillard.com/2018/04/09/automate-workflow-deployment-in-apache-nifi-with-the-nifi-registry/)

- [https://dzone.com/articles/devops-for-apache-nifi-17-and-more](https://dzone.com/articles/devops-for-apache-nifi-17-and-more)

- [https://community.cloudera.com/t5/Community-Articles/Big-Data-DevOps-Apache-NiFi-Flow-Versioning-and-Automation/ta-p/247976](https://community.cloudera.com/t5/Community-Articles/Big-Data-DevOps-Apache-NiFi-Flow-Versioning-and-Automation/ta-p/247976)

Some newer features in 1.8, 1.9, 1.10, 1.11 that you need to use.

- [https://blogs.apache.org/nifi/entry/load-balancing-across-the-cluster](https://blogs.apache.org/nifi/entry/load-balancing-across-the-cluster)

- [https://community.cloudera.com/t5/Community-Articles/Offload-NiFi-Cluster-Nodes-using-the-UI-NiFi-1-8-0/ta-p/249070](https://community.cloudera.com/t5/Community-Articles/Offload-NiFi-Cluster-Nodes-using-the-UI-NiFi-1-8-0/ta-p/249070)

- [https://www.datainmotion.dev/2019/10/apache-nifi-load-balancing-via-load.html](https://dev.to/tspannhw/apache-nifi-load-balancing-via-load-balanced-connections-593m)

- [https://medium.com/@abdelkrim.hadjidj/best-practices-for-using-apache-nifi-in-real-world-projects-3-takeaways-1fe6912101db](https://medium.com/@abdelkrim.hadjidj/best-practices-for-using-apache-nifi-in-real-world-projects-3-takeaways-1fe6912101db)

- [https://docs.cloudera.com/HDPDocuments/HDF3/HDF-3.5.1/nifi-configuration-best-practices/hdf-nifi-configuration-best-practices.pdf](https://docs.cloudera.com/HDPDocuments/HDF3/HDF-3.5.1/nifi-configuration-best-practices/hdf-nifi-configuration-best-practices.pdf)

- [https://www.datainmotion.dev/p/links.html](https://www.datainmotion.dev/p/links.html)

Advanced Articles:

- [https://community.cloudera.com/t5/Community-Articles/Dissecting-the-NiFi-quot-connection-quot-Heap-usage-and/ta-p/248166](https://community.cloudera.com/t5/Community-Articles/Dissecting-the-NiFi-quot-connection-quot-Heap-usage-and/ta-p/248166)

- [https://digitalplumber.me/2018/01/15/the-power-of-the-advanced-button-on-nifis-updateattribute-processor/](https://digitalplumber.me/2018/01/15/the-power-of-the-advanced-button-on-nifis-updateattribute-processor/)

- [https://community.cloudera.com/t5/Community-Articles/ETL-With-Lookups-with-Apache-HBase-and-Apache-NiFi/ta-p/248243](https://community.cloudera.com/t5/Community-Articles/ETL-With-Lookups-with-Apache-HBase-and-Apache-NiFi/ta-p/248243)

- [https://medium.com/@abdelkrim.hadjidj/data-flow-enrichment-with-apache-nifi-d221f1dde419](https://medium.com/@abdelkrim.hadjidj/data-flow-enrichment-with-apache-nifi-d221f1dde419)

- [https://community.cloudera.com/t5/Community-Articles/Update-the-Contents-of-FlowFile-by-using-UpdateRecord/ta-p/248267](https://community.cloudera.com/t5/Community-Articles/Update-the-Contents-of-FlowFile-by-using-UpdateRecord/ta-p/248267)

- [https://community.cloudera.com/t5/Community-Articles/Optimizing-Performance-of-Apache-NiFi-s-Network-Listening/ta-p/246072](https://community.cloudera.com/t5/Community-Articles/Optimizing-Performance-of-Apache-NiFi-s-Network-Listening/ta-p/246072)

Spaghetti is for eating, not for real-time data streams.   Let's keep it that way.

  

If you are not sure what to do check out the[Cloudera Community](http://community.cloudera.com/), NiFi [Slack](http://apachenifi.slack.com/) or the NiFi [docs](https://nifi.apache.org/docs/nifi-docs/).   Also I may have a helpful article here. Join me and my NiFi friends at virtual [meetups](https://www.meetup.com/futureofdata-princeton/) for more in-depth NiFi, Flink, Kafka and more. We keep it interactive so you can feel free to ask questions.

  

**Note** :   In this picture I am in Italy doing spaghetti research.  
  
  

[![](https://1.bp.blogspot.com/-s-sUBaJ1tvU/Xteyb9eGzwI/AAAAAAAAagw/k5L_YE6-96k2rwO5Kid5Yvqvye2nGQg5QCK4BGAsYHg/w480-h640/IMG-5670.jpg)](https://1.bp.blogspot.com/-s-sUBaJ1tvU/Xteyb9eGzwI/AAAAAAAAagw/k5L_YE6-96k2rwO5Kid5Yvqvye2nGQg5QCK4BGAsYHg/IMG-5670.jpg)