Create or use an existing content type for your nodes.
Add a field (field_ext_id
) on the content type to track your external content id.
When building your page, use EntityFieldQuery (note that it may have performance implications on very large sites) to look for a node with field_ext_id = your id
.
If no node found, create one:
$node = new stdClass;
$node->type = 'your_content_type';
$node->status = 1;
$node->uid = 1;
$node->title = 'my node';
$node->created = REQUEST_TIME;
$node->updated = REQUEST_TIME;
// set your other field values (including field_ext_id), as necessary
node_save($node);
// your new node's id is now available as $node->nid
For working with fields, have a look at Rendering Drupal 7 Fields The Right Way and Entity Metadata Wrapper.