GraphAware Module for Expiring (Deleting) Nodes and Relationships
Failed to load latest commit information.
src update to 3.1.0 Dec 13, 2016
.gitignore finalise first feature-complete version Mar 13, 2016
.travis.yml update to 3.1.0 Dec 13, 2016
gpl.txt Initial Commit Jan 15, 2016
pom.xml [maven-release-plugin] prepare for next development iteration Dec 13, 2016

GraphAware Neo4j Expire

Build Status | Products | Downloads | Javadoc | Latest Release:

GraphAware Expire is a simple library that automatically deletes nodes and relationships from the database when they've reached their expiration date or time-to-live (TTL).

Getting the Software

Server Mode

When using Neo4j in the standalone server mode, you will need the GraphAware Neo4j Framework and GraphAware Neo4j Expire .jar files (both of which you can download here) dropped into the plugins directory of your Neo4j installation. After changing a few lines of config (read on) and restarting Neo4j, the module will do its magic.

Embedded Mode / Java Development

Java developers that use Neo4j in embedded mode and those developing Neo4j server plugins, unmanaged extensions, GraphAware Runtime Modules, or Spring MVC Controllers can include the Expire Module as a dependency for their Java project.


Releases are synced to Maven Central repository. When using Maven for dependency management, include the following dependency in your pom.xml.



To use the latest development version, just clone this repository, run mvn clean install and change the version in the dependency above to

Note on Versioning Scheme

The version number has two parts. The first four numbers indicate compatibility with Neo4j GraphAware Framework. The last number is the version of the Expire library. For example, version is version 1 of the Expire library compatible with GraphAware Neo4j Framework

Setup and Configuration

Server Mode

First, please make sure that the framework is configured by adding dbms.thirdparty_jaxrs_classes=com.graphaware.server=/graphaware to conf/neo4j.conf, as described here.

And add this configuration to register the Expire module:


#EM becomes the module ID (you will need to use this ID in other config below):

#If you want to delete nodes at a certain time, configure the node property (in this case "expire")
#that holds the expiration time in ms since epoch:

#Alternatively, if you want to delete nodes after some time has elapsed since they have been created,
#configure the node property (in this case "ttl") that holds the TTL in ms:

#If you want to delete relationships at a certain time, configure the relationships property (in this case "expire")
#that holds the expiration time in ms since epoch:

#Alternatively, if you want to delete relationships after some time has elapsed since they have been created,
#configure the relationships property (in this case "ttl") that holds the TTL in ms:

#If you want to delete expired nodes despite that fact they still have relationships, set the strategy to "force".
# This setting defaults to "orphan", which will only delete expired nodes with no relationships:

#By default, all created/updated nodes and relationships are checked for the presence of expire/ttl property.
#As with most GraphAware Modules, nodes and relationships this module applies to can be limited by the use of SPeL, e.g.:

Embedded Mode / Java Development

To use the Expire module programmatically, register the module like this

 GraphAwareRuntime runtime = GraphAwareRuntimeFactory.createRuntime(database);  //where database is an instance of GraphDatabaseService
 ExpirationModule module = new ExpirationModule("EXP", database, ExpirationConfiguration.defaultConfiguration().withNodeTtlProperty("ttl").withRelationshipTtlProperty("ttl"));


 GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(pathToDb)

 //make sure contain the lines mentioned in previous section

Using GraphAware Expire

Apart from the configuration described above, the GraphAware Expire module requires nothing else to function. It will delete nodes and relationships when they've reached their expiration date or TTL. In case both expiration date and TTL are set, the module takes into account whichever one is later. Please note a few more facts of interest:

  • by default, nodes are only deleted if they have no relationship (i.e. all relationships have expired or have been manually deleted), unless the node expiration strategy is set to "force".
  • when ttl property gets updated, the time-to-live is counted from the moment the node has been updated
  • one of the following must be configured, otherwise it does not make sense to use the module: nodeExpirationProperty, nodeTtlProperty, relationshipExpirationProperty, relationshipTtlProperty.

Advanced Config

Nodes and relationships, along with their expiration dates, are stored in Neo4j's legacy index, completely transparently to the user. A GraphAware Framework Timer-Driven Runtime Module checks for expired nodes and relationships every time it is asked to perform work, and deletes the ones that are found.

Please note that the default setting for the Timer-Driven Runtime Module is and "adaptive" strategy that it slows down background processing when the database is busy. By default, the maximum delay between invocations is 5 seconds. If you want a shorter and/or more predictable time between a node/relationship reaching its expiration date and actually being deleted, you can change this strategy. For example, if you wanted to check for expired elements every 100ms consistently, you could add the following lines to



Copyright (c) 2016 GraphAware

GraphAware is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see